Create Docker image

For research reproducibility, a Docker image gives a known software state that should be usable for many years. It isn’t strictly necessary to make a custom image as described below, but it can be useful for a known software state.


Create a Docker image by using a Dockerfile. If desired to set environment variables, use ENV Dockerfile instruction.

FROM alpine:latest

# example for CMake project using Fortran with OpenMPI.
RUN apk add --no-cache ninja-build cmake gfortran openmpi-dev

ENV CMAKE_GENERATOR=Ninja

Create the file above named Dockerfile in the Git repo.

apk
Alpine package manager

Build the Docker image:

docker build -t openmpi-fortran .

from the same directory as Dockerfile

Check the image exists–it may be nearly 500 MB:

docker images

Before committing for upload, invoke the container.

docker run openmpi-fortran

This will almost immediately start and stop, as it didn’t have a command to run or persist.

Get the hexadecimal container ID by:

docker ps -a

The container will have an auto-assigned name. Note the hexadecimal “Container ID”.

upload Docker image

Once the configured Docker container is ready, share this container. This can be done with Docker Hub.

Once ready to upload the image, note the “container ID”, which is the hexadecimal number at the terminal prompt of the Docker container, under docker ps. The container hex ID must appear under docker ps, just being in docker images is not enough.

docker commit -m "Fortran Dockerfile setup" hex_id dockerhub_username/openmpi-fortran

The changes to the image the container made are gathered into a new image. It may take a minute or two for a large image. Ideally with a small image it will take only a couple seconds. The new image has not yet left the computer, it will show up under

docker images

Once uploaded, the Docker image is visible to the world by default.

Login to Docker Hub

docker login -u dockerhub_username

Push (upload) this image to Docker Hub. This image is world-visible by default!

docker push dockerhub_username/openmpi-fortran

If the image is very large > 1 GB, be aware it will take a while to upload, and for the host to download. This is a telltale that it’s important to keep Docker images small.