How to set up Docker for Deep Learning with Ubuntu 16.04 (with GPU)

In this tutorial, I will guide how you set up your computer as a work station to do some serious deep learning while managing different development environments with Docker. First let’s get the machine to running without any docker.

  1. Install Ubuntu 16.04 (the latest version with LTS)
  2. Install the latest (supported by your GPU) Nvidia drivers.
  3. Install CUDA (which allows fast computation on your GPU).
  4. Install the CUDA Toolkit
  5. Install cuDNN (install from Debian files)
  6. Now to verify that everything works as expected, follow the steps, I had to fix some bugs in the sample code as described in this blog post.
  7. Now run it again, ‘all test passed!’ should be the last command.

Now let’s focus on Docker.

  1. Install Docker
  2. Install nvidia-docker in order to get access to the GPU inside the docker container
  3. Write a scrip to run a Docker container. This pulls an image from floydhub, removes the need for a password with Jupyter, persits Jupyter Notebooks in $HOME/jupyter and makes the notebook accessible on port 8888.

    #!/usr/bin/env bash docker run -it -p 8888:8888 –runtime=nvidia –volume /home/filter/jupyter:/jupyter –name pytorch floydhub/pytorch:0.3.1-gpu.cuda9cudnn7-py3.27 /bin/sh -c “./run_jupyter.sh –NotebookApp.token=” –notebook-dir=/jupyter”

  4. Now verify your docker is working `docker ps` 5. To stop it run `docker stop pytorch` or to restart `docker restart pytorch`.

    1. To access the work borks from your local machine, tunnel the traffic via ssh E.g. `ssh -N -f -L localhost:8888:localhost:8888 @` If you happened to have a special setup (like myself) that you don’t have a IPv6 address, you may need to tunnel it over an another server. In this case, 1) tunnel from the local machine to the server and ssh -N -f -L localhost:8888:localhost:64149 jfilter@vis.one 2) tunnel from that server to your gpu work stations. ssh -N -f -L localhost:64149:localhost:8888 filter@filter.dynv6.net That’s it. I hope this post helpful to you and you are right to train deep neural networks on large datasets. ;)