Deep Learning part 1: Dockerized GPU Environment (AWS)

It was time to do deep learning experiments. As always, the first thing was to set up an appropriate environment. This post offers a rough outline how to install a Dockerized GPU deep learning environment in AWS EC2.

Why GPU?

GPU offers significant speed-ups to training and running deep learning models. Models have a huge amount of parameters and GPUs are able to do calculations on these parameters in parallel. Check this CPU vs GPU article by a certain GPU provider.

Why cloud?

My mac doesn’t support GPU computations so I had to use AWS EC2 GPU instance (g2.2xlarge). g2.2xlarge has 15GB memory and a scalable EBS storage (25 GB in this case). The cost for the instance was about ~0.45€/hour (as a spot instance).


Setting up the system required some amount of tinkering. Most of the time was spend with CUDA, cuDNN and Nvidia drivers. Dockerizing the environment made matters even more complicated. Docker shares the host’s resources (including GPU) so Docker had to be configured to communicate with host’s GPU. Luckily, Nvidia has a Docker wrapper, which did the trick.

Installing Lasagne, Theano and other Python libraries was really simple after Docker was correctly configured. Lasagne offers a thorough guide for installation.

Follow these steps to get your system up and running:

1) Get an AWS instance with GPU support

2) Install Docker to your AWS instance. Docker for Docker.

3) Install Nvidia-cuda to your AWS instance. Select OS and architecture and you will find installation commands from below.

4) Install Nvidia’s Docker wrapper (nvidia-docker). Enables GPU on Docker instances.

5) Install Lasagne (or any other DL library) and pre-requisities in Docker container or create a reusable Dockerfile.

6) Test with nvidia-smi: sudo nvidia-docker run -it deep_learn nvidia-smi




Notice that the instance is run with nvidia-docker, not with plain docker.

After hours and hours it was up!