Docker (deprecated)

From AG Euler Wiki
(Redirected from Docker)
Jump to navigation Jump to search

What is docker?

Docker is a platform for running virtual machines called containers. These are functionally analogous to the operating systems on a computer, though you can run them from within your operating system. They are useful because they create lightweight, customisable environments within which you can run software. This is particularly helpful when you have programs which have very particular dependencies, or require a linux base installation in order to function correctly. You can read more about Docker here.

What do we use docker for?

The Euler group is currently using docker to host our two Jupyter notebook servers, though in the past we have also used it for hosting a MySQL server. To see what containers are currently running, ssh into 'cn31' and enter the command:

docker ps

This will return a list of the currently active docker containers, the images they are built from, how long they have been online and what ports they are forwarded to.

How do I build my own docker containers?

New docker containers can be built using the command:

docker run [-tags] [imageName]

For example, to build a new scipyserver called 'miranda', forwarded to port 1948 on localhost with the password 'uranus', you would enter:

docker run -d -p 1948:8888 --name miranda -e "PASSWORD=uranus" -e DISPLAY=$DISPLAY ipython/scipyserver

Each of the -tags has a unique function in building the server. The last entry specifies the image from which the container is built, in this case an ipython server. You can find more images over at Dockerhub.

Tag Function
-d Run in the background
-p 1948:8888 Forward port 8888 to 1948
--name miranda Specify container name as miranda
-e "PASSWORD=uranus" Set password to uranus
-e DISPLAY=$DISPLAY Needed for plotting in Jupyter
-v Mount volume, see below
--help Show different tag options for given command

Data stored in docker containers is transient and is lost when the container is deleted. In order to set the containers so that they can access volumes on the host system and persist their content after they are deleted, we have to use additional tags to mount directories in the container to directories on the host system. Here is an example of this for another ipython server:

docker run -v ~/Notebooks:/notebooks/Notebooks -v ~/Data:/notebooks/Data:ro -v /tmp/.X11-unix:/tmp/.X11-unix:ro ipython/scipyserver

Here, three different directories have been mounted: a volume which the container can write to, under notebooks/Notebooks, a volume which the container can read, under notebooks/Data (the :ro tag specifies read only), and a further folder used for X11 forwarding, which is necessary for getting figures in the Jupiter server.

For a more thorough walkthough, see the official Getting Started documentation.