Docker for the Macintosh has recently emerged from beta and I’m ecstatic.
Docker implements a way of walling off a piece of software from the underlying operating system using a tech they call “containers”.
This is an absolute godsend for deploying services. One of the problems in system administration is the cost and complexity of spinning up a new service and then removing it from a computer once it is no longer required.
Software when it is installed and run can spray pieces of itself all over the computer’s file system and getting it out again is difficult.
Previously we have used virtual machines to isolate this problem. That has it’s own costs, a virtual machine means you are running (at least) two complete operating systems on the hardware. It also has a cost in memory and hard disk space.
Containers lower the cost considerably. They have all the advantages of virtual machines but share the operating system kernel with each other and the underlying OS. This makes them smaller and consuming considerably less resources than virtual machines. This also makes them quicker to download and deploy.
Since Docker is open source it means that there is now a huge community around it. Docker containers are easily available for a huge range of applications, a quick visit to Dockerhub will show you how large.
Docker containers may well be the holy grail of app deployment. They certainly tick all the boxes system administrators require.
So how easy is it to use? Installing it is trivial, just download the install package and copy the Docker application to your Applications folder. You might also want to download
Kitematic which provides a GUI interface to Docker, it also just requires downloading and copying the app to your Applications folder. It is just as easily installed on a Linux box.
You can also install bash completion for docker with this
curl -XGET https://raw.githubusercontent.com/docker/docker/master/contrib/completion/bash/docker >
I wish I could tell you how easy it is to build a Docker container from scratch but every time I searched DockerHub for a container I wanted someone else had already built it, or built a large chunk of it.
As an example, I wanted a container running Python 3, Jupyter and the add-on for bash notebooks. Sure, I could have built it from scratch but Continuum, the Anaconda people, already have a Docker container with Python 3 and Jupyter (along with a bunch of other useful Python libraries) installed so :-
docker run -it continuumio/anaconda3 /bin/bash
which will download and run the Python 3 version of Anaconda in a container. Then when the container runs (the
-it makes it an interactive container) :-
pip install bash_kernel
python -m bash_kernel.install
then exit the container and at the terminal prompt
docker ps -a
docker commit <container_name> tonyw/jupyter
ps -a lists all the containers so I know which one to commit and the commit saves the changed container with (optionally) a new name. Now we can run the new container.
docker -d -p 8888:8888 -v /Users:/Users -rm tonyw/jupyter
jupyter notebook --ip='*' --port=8888
This runs the Docker container in ‘daemon’ mode and when the container starts runs the command at the end, in this case Jupyter in notebook mode.
Of course if I just want to run Python 3.5 instead of Jupyter I can always replace the
-it and the jupyter command with
bash and I get a shell in the container.
Now all the Docker gurus out there are screaming at me that I should use a Dockerfile to build my custom container and define all sorts of magical stuff like the default command to run when the container starts and the working directory and all the rest so I didn’t need them all in my long command line. Frankly, while that would probably be a good idea I haven’t quite managed to learn how to do all that automated magic and it almost seems like too much work.
Perhaps for my next blog post.
Pepijn Bruienne’s talk on Docker from PSU MacAdmins 2015