Docker: a Primer

René-Jean Corneille
7 min readMar 5, 2019

Docker is an application allowing to manage Linux containers on top of an existing OS. It provides a virtualisation layer (the Docker Engine) and thus any command and operations ran inside the container remain the same regardless of the OS on which Docker is set up. Docker relies solely on the host OS as a result the only compatibility issue we can run into is whether the OS supports Docker: this simplifies greatly sharing of code and transitioning from development to production.

Containers have a great advantage compared to traditional virtual machines is that they are lightweight as they do not include an OS which makes them easy to share. As a matter of fact the Docker Hub is a repository of images shared by developers and contains more than 400K images. As a good practice, I always use images from the official repository.

Screenshot of dockerhub

Docker runs natively on Linux so it is straightforward to setup on a Linux machine. In general, running Docker on anything other than Linux comes with its challenges. I focus on the basic pitfalls when working with the application on MacOS, though I still explain how to set it up on Linux distributions.

1. Installation

Docker can be installed easily on MacOS with homebrew:

$ brew install docker

On MacOS, we need some sort of virtual machine that runs part of Linux required by Docker: the docker-machine. VirtualBox is the virtualisation layer allowing docker-machine to run on MacOS:

$ brew cask install virtualbox

Thus (and this is important to understand especially for networking) the host OS is not MacOS but the virtual machine itself.

How docker runs on MacOS?

On Linux docker can be installed using the native package manager apt-get:

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
$ sudo add-apt-repository “deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable”
$ apt-cache policy docker-ce
$ sudo apt-get install -y docker-ce

Docker reads a Dockerfile that specifies the base image (from Docker Hub) to build a…

--

--

René-Jean Corneille

Director of ML. I write about data science, mlops, python and sometimes C++