Docker Containers
Docker containers are portable containers that bundle together software and dependencies in a way that can be run on many host operating systems, including Linux, Windows, and MacOS. Docker containers run on the host system managed by the Docker daemon which runs as a background process.
Unfortunately, Docker containers by themselves are not suitable for high performance computing systems (see the HPC section for more information).
The Dockerfile
The Dockerfile specifies how a Docker image is built and what dependencies are installed. This example refers to the container_definitions/Dockerfile_serial file in the tutorial GitHub repository.
The FROM Line
The FROM line specifies what base image to use (by default, from Docker Hub).
FROM ubuntu:20.04
In our example, we pull the ubuntu:20.04 image from Docker Hub, a cloud library of Docker images.
Dependencies and Installation
Next, we set an environment variable and run a command to deal with setting timezone data required to install some packages:
# from https://rtfm.co.ua/en/docker-configure-tzdata-and-timezone-during-build/ ENV TZ=America/Chicago RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone # endfrom
And then install our dependencies:
RUN apt-get update && apt-get -y install libhdf5-dev libeigen3-dev cmake g++
Copying Files
Next, we copy src/main.cpp and CMakeLists.txt into the container:
COPY src/main.cpp /src/main.cpp COPY CMakeLists.txt /CMakeLists.txt
Installing random_matrix
Finally, we can build our random_matrix code from the example GitHub repository and then clean up the dependencies.
RUN mkdir build && cd build && cmake .. && make && make install RUN apt-get remove -y libhdf5-dev libeigen3-dev cmake g++
Creating the Data Mount Point
Now we end by creaing a directory in the container to serve as a filesystem mount point.
RUN mkdir /data
Building Docker Containers
To build a Docker container, navigate to the root of the example project and run the following command:
docker build . -t random_matrix:latest -f container_definitions/Dockerfile_serial
This will create a docker image, managed by the daemon (so it won't appear as a file), called random_matrix:latest using the Dockerfile container_definitions/Dockerfile_serial.
Running Docker Containers
To start up our random_matrix Docker container, we can execute the command
docker run -d -it --name random_matrix --mount type=bind,source="$(pwd)",target=/data random_matrix:latest
Then, to run the random_matrix program in the container, we can run
docker exec -it -w /data random_matrix random_matrix 30 40