Overview #

The creation of Docker images is done via files named Dockerfile. One of Docker’s strengths is that Dockerfiles are easy to write and therefore, the rolling out of software can be automated without any problems.

The typical components of a Dockerfile are:

  • FROM defines a base image on which the installation is based. A base image for a microservice usually contains a Linux distribution and basic software, such as the JVM, for example.

  • RUN defines commands that execute to create the Docker image. In essence, a Dockerfile is a shell script that installs the software.

  • CMD defines what happens when the Docker container is started. Typically, only one process should run in one Docker container. This is started by CMD.

  • COPY copies files in the Docker image. ADD does the same; however, it can also unpack archives and download files from a URL on the Internet. COPY is simpler to understand because it does not extract archives, for example. Also, from a security perspective, it can be problematic to download software from the Internet into Docker containers. Therefore, COPY should be given preference over ADD.

  • EXPOSE exposes a port of the Docker container. This can then be contacted by other Docker containers or can be tied to a port of the Docker host.

A comprehensive reference is available on the Internet which contains additional details to the commands in Dockerfile.

An example for a Dockerfile #

A simple example of a Dockerfile for a Java microservice looks like this: