Creating Docker Images
In Docker lingo it is important to distinguish between an image and a container.
A Docker image is what we make when we get when we run the
docker build command. A
Docker container is a running instance of an image, that is, what we get when we
docker run command. It is possible to have many running containers started from a single image.
The FROM directive specifies the base image that will be used for the current image.
In the LAPPS Grid all images will either be based on one of the
lappsgrid/* images or one
of the Galaxy images (typically in the
The following Lappsgrid images are available:
- lappsgrid/ubuntu - Ubuntu 14.04 with:
- JDK 1.7
- PostgreSQL 9.3
- emacs, nano, curl, wget, zip, and unzip
- lappsgrid/tomcat - Extends the lappsgrid/ubuntu image and adds Tomcat 7.
The COPY directive takes two parameters, a source and a destination, and as the name suggests, copies the source file to the destination in the image being built.
COPY ./file.txt /usr/local/share/file.txt
The above copies file.txt to the /usr/local/share directory in the image being created.
Docker will only copy files from the current directory. You cannot specify an arbitrary path as the source.
The ADD directive is the same as the COPY directive except it does some extra magic. In particular, the ADD directive will decompress any files when it copies them to the target.
The ADD directive’s source parameter can also be a URL, in which case Docker will download the file pointed to by the URL and copy it to the target image.
ADD http://example.com/file.tgz /usr/share
The RUN directive can be used to execute arbitrary commands when building the image,
RUN chmod ug+x /usr/local/share/file.txt
Long commands can be be split into several lines with the line continuation character \ and multiple commands can be run in sequence by joining them with the AND (&&) operator.
RUN apt-get update && apt-get upgrade -y && \ apt-get install package1 package2 pacakge3 && \ chmod u+x /usr/bin/startup.sh
The USER directive specifies the user account subsequent command will be RUN as.
USER joe RUN echo 'some data' > /home/joe/file.txt && \ chmod a+r /home/joe/file.txt USER root RUN apt-get install -y package1 package2 package3
The CMD directive specifies the command that will be run when the container is launched. When this command terminates the Docker container will exit.