In this hands-on exercise, we will learn how to create and use a reproducible computational environment with Docker.
You must already have Docker installed. See the Docker installation documention for more information.
In general this means having a properly configure kernel and the docker client
and daemon installed on a Linux distribution. On Mac or Windows, the
installation installation instructions will install a boot2docker
utility to
manage a VirtualBox virtual machine running the docker client and daemon.
We need to build the Docker images, our reproducible computational environments. Docker images are built from a set of instructions, the Dockerfile.
After changing to the current directory scipy-tutorial-2014/environement/docker
,
build the base image via:
It's also possible to use the pregenerated Docker image from the Docker Hub, via:
To launch the base image and open a shell:
You are now in a Docker container. The -i -t flags tells docker to start
up a pseudo-terminal and keep stdin open. Enter exit
to exit the shell.
This runs the Docker container in the background, makes the ports listening available on the host, mounts the current working directory, and gives the container the name ipython.
We can also configure containers to perform unattended tasks.
We can build other images on top of reproducible/base
to handle common tasks.
The Dockerfile-dexy
image is used to run the dexy
command.
Here's the Dockerfile:
# Runs the command "dexy"
FROM reproducible/base
MAINTAINER Ana Nelson <ana@ananelson.com>
CMD dexy setup && dexy
It's built via:
And run via:
This mounts the scipy-tutorial-2014/dexy
directory within the container and
then runs dexy. The dexy-generated output files are present on your local file
system after the container exits because of the volume mounting.
The Dockerfile-ipython
image is used to launch the IPython notebook server.
Here's the Dockerfile:
# Runs the ipython notebook
FROM reproducible/base
MAINTAINER Ana Nelson <ana@ananelson.com>
CMD ipython notebook --ip=* --pylab=inline --no-browser
EXPOSE 8888
It's built via:
To launch a non-interactive container which will run the IPython notebook server and forward the port IPython is running on, do:
To get information on the containers running and the ports available from a given container,
If this returns 0.0.0.0:49153, we will use the 49153 port. On Linux, point
your browser to http://localhost:49153. On Mac on
Windows, use boot2docker
to find the correct IP address,
boot2docker ip
If this returns 192.168.59.103, then point your browser to http://192.168.59.103:49153.
To stop and remove the container:
For a full list of docker commands or docker subcommand help, enter docker or docker subcommand with no arguments.
$ docker help
Usage: docker [OPTIONS] COMMAND [arg...]
-H=[unix:///var/run/docker.sock]: tcp://host:port to bind/connect to or unix://path/to/socket to use
A self-sufficient runtime for linux containers.
Commands:
attach Attach to a running container
build Build an image from a Dockerfile
commit Create a new image from a container's changes
cp Copy files/folders from the containers filesystem to the host path
diff Inspect changes on a container's filesystem
events Get real time events from the server
export Stream the contents of a container as a tar archive
history Show the history of an image
images List images
import Create a new filesystem image from the contents of a tarball
info Display system-wide information
inspect Return low-level information on a container
kill Kill a running container
load Load an image from a tar archive
login Register or Login to the docker registry server
logs Fetch the logs of a container
port Lookup the public-facing port which is NAT-ed to PRIVATE_PORT
pause Pause all processes within a container
ps List containers
pull Pull an image or a repository from the docker registry server
push Push an image or a repository to the docker registry server
restart Restart a running container
rm Remove one or more containers
rmi Remove one or more images
run Run a command in a new container
save Save an image to a tar archive
search Search for an image in the docker index
start Start a stopped container
stop Stop a running container
tag Tag an image into a repository
top Lookup the running processes of a container
unpause Unpause a paused container
version Show the docker version information
wait Block until a container stops, then print its exit code