How Docker changed my life

Roger Schaer
Jan 23 · 3 min read

Deploying machine learning has never been this easy!

“I try all things, I achieve what I can” — Herman Melville, Moby Dick

How many times have you wasted a day to install the same set of Python libraries, setting up the same environment on a different machine? Literally too many times!

Research should be about amazing new insights, and not annoying technical issues.

Docker lets you focus on the essentials and forget about the deployment details. In 19 words, Docker lets you bundle an application with all its dependencies into a self-sufficient package (called container) that can run anywhere.

If you’re anything like me, you’ve spent a lot of time installing Anaconda, setting up virtual environments and then running into conflicts between different versions of Python, libraries, frameworks, binaries, etc. And when it finally works on your machine, you want to run the same thing on a server. There you go again, repeating the whole procedure and running into new, unexpected errors.

And that’s where Docker came to my rescue: in very few steps, I was able to have a working environment with everything I need (Python, CUDA, TensorFlow, Jupyter Notebook, access to the GPU, etc.). Even better, I was then able to reuse the exact same setup on a remote server, without any hassle. Finally, I have reproducible experiments that work everywhere and will keep working even in a year.

Here’s what you need:

  1. Install Docker
  2. Install the NVIDIA drivers (if you’re using a GPU)
  3. …that’s it!

From here, you’re just one command away from doing Deep Learning:

docker run \
--name mobydock \
-v ~/Desktop/notebooks/:/tf/notebooks \
-p 8888:8888 \
tensorflow/tensorflow:latest-gpu-py3-jupyter

So what’s happening above?

  • First of all, docker run is the command to start a new container with a given application.
  • The name parameter just gives a name to the created container.
  • The v parameter allows mapping a folder from your computer inside the created container, in order to access your Jupyter notebooks for example.
  • The p parameter allows mapping a network port from the host to the container, in order to access the service running inside the container.
  • tensorflow/tensorflow:latest-gpu-py3-jupyter is the name of the Docker image to run (basically what application we want to run). This image contains everything needed and automatically starts a Jupyter Notebook server.

From there, you can directly access Jupyter in your browser, using the URL shown in your terminal:

You can access the notebooks in the mapped folder by clicking on notebooks. From here, it’s business as usual, simply write, edit and run your code (example):

And this doesn’t work just for Jupyter or TensorFlow, any Python code and libraries can be added (PyTorch, scikit-learn, keras, OpenCV, etc.). There are a lot of public images available for many different purposes on Docker Hub. If you don’t find what you need, you can always create your own image or customize an existing one.

Stay tuned for a second article explaining how you can combine Docker with the awesome Visual Studio Code editor in order to run and debug your code locally or even on a remote server!

Bye bye, Anaconda!

Thanks to all our team members for the contribution Juan Sebastian Otálora Montenegro, Ivan Eggel, Niccolomarini, Recurrent Pi.

Roger Schaer

Written by

research at medgift

Sharing concepts, algorithms and research topics in our lab

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade