Docker Fortran image

Docker images are useful for reproducibility and ease of setup and for software binary distribution on platforms not natively available. For example, it may be desired to distribute a statically-linked binary that will run on any Linux system with compatible CPU architecture and kernel system calls.

To setup and maintain Docker images, it’s useful to have Docker Desktop available on the developer laptop to debug and test Dockerfiles. Read the install instructions particular to the laptop OS to understand OS-specific caveats and features. For example, on Linux laptops, to avoid the need for “sudo” in every command, follow the post-install.

Run a Docker container

Docker commands can be run from the system terminal if desired–all commands in this article assume this. Docker images by default will be downloaded to run locally.

Try the Hello World images, which should auto-download and print a welcome message

docker run hello-world

Search for a desired image using Docker Desktop or docker search. Consider the “Official” images first. Let’s use Alpine Linux.

docker search alpine

Get the desired image

docker pull alpine

Verify the images:

docker images

Start the Docker container:

docker run -it alpine
-it
interactive session

Verify the Alpine version running in the container. It will have a # superuser prompt.

cat /etc/os-release

Search for desired APK packages from within the container:

apk update
apk search gfortran

Verify the MUSL C library version like:

ldd

manage containers

These commands are issued NOT from a system Terminal, not the Docker container.

  • list images: docker images -a

  • list containers (running and stopped): docker ps -a

  • stop a Docker container: docker stop container_name

  • start a Docker container: docker start container_name

  • login to a running Docker container: docker exec -it container_name

  • get container environment variables: docker exec container_name env

  • cleanup unused containers docker system prune

Each docker exec command is a new shell instance. Changing directories in one docker exec has no effect on subsequent commands for example.