How to Set Up Docker for Deep Learning With Ubuntu 16.04 (With GPU)

by Johannes Filter, Apr 15, 2018

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), an updated verison for Ubuntu 18.04
  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 bash

    docker restart pytorch
    
  6. To access the work borks from your local machine, tunnel the traffic via ssh

    ssh -N -f -L localhost:8888:localhost:8888
    
  7. (optional) 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,

  8. tunnel from the local machine to the server

    ssh -N -f -L localhost:8888:localhost:64444 XX@XX.TLD
    
  9. tunnel from that server to your gpu work stations

    ssh -N -f -L localhost:64444:localhost:8888 XX@XX.TLD
    

That’s it. I hope this post helpful to you and you are right to train deep neural networks on large datasets. ;)