Deploying machine learning has never been this easy!
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:
From here, you’re just one command away from doing Deep Learning:
docker run \
--name mobydock \
-v ~/Desktop/notebooks/:/tf/notebooks \
-p 8888:8888 \
So what’s happening above?
- First of all,
docker runis the command to start a new container with a given application.
nameparameter just gives a name to the created container.
vparameter allows mapping a folder from your computer inside the created container, in order to access your Jupyter notebooks for example.
pparameter 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-jupyteris 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!