Skip to main content
  1. Blog/

Docker container for SAGA geoacoustic inversion software

Table of Contents


For my research in geoacoustic parameter estimation, I have to be able to use code that was written in Fortran two or three decades ago. Specifically, my advisor wrote a geoacoustic inversion program called SAGA that can estimate a range of geoacoustic properties using various acoustic propagation models. Sometimes it’s nice to be able to compare results from techniques that I’m working on to results from legacy approaches.


Seismo Acoustic inversion using Genetic Algorithms


Fortran has a reputation for being antiquated and difficult to work with. However, once compiled correctly, it runs extremely quickly, which is a must for scientists running large computational models. Most of the challenges I have encountered occur when configuring and running the Fortran compiler. This requires some knowledge of how Fortran is compiled, and configurations are unique to individual operating systems and CPU architectures. Perhaps most frustrating is that I’m not compiling or installing Fortran programs often enough to be able to remember how I did it previously. But even when I keep good notes of steps I take, operating system updates can sometimes break libraries that are required for the compiler to run. I experienced this with a separate Fortran program when I was unable to use the GFortran compiler after a MacOS update, and forced me to adopt Intel’s Fortran compiler.

Docker container setup

To avoid these frustrations, I decided to use Docker to set up the necessary environment for compiling SAGA. The dockerfile I used is:


RUN yum update -y
RUN yum install -y gcc-gfortran gdb git make vim
RUN git clone
ENV FORTRAN=gfortran
RUN bash ./
RUN make clean && make all

A few comments on the dockerfile:

  • Line 1: I specify Redhat’s Linux distribution to match the remote server I normally work on.
  • Line 3: Install the following packages: Fortran compiler gcc-gfortran, debugger gdb, git for version control, make to compile SAGA, and vim to edit files within the container environment.
  • Line 4: Clone the SAGA repository into the container.
  • Line 5: Specify the working directory for SAGA.
  • Line 6: Specify the host architecture.
  • Lines 7-13: Install SAGA using a setup script.

Setup script

The setup script is necessary to add the SAGA working and bin directories to the container’s system path:

( echo "" ; echo "# >> Begin SAGA Configuration <<" ) >> ~/.bashrc
echo "export FORTRAN=$FORTRAN" >> ~/.bashrc
echo "export HOSTTYPE=$HOSTTYPE" >> ~/.bashrc
echo "export PATH=$SAGADIR/bin:$SAGADIR/bin/$HOSTTYPE-$FORTRAN:$PATH" >> ~/.bashrc
echo "# >> End SAGA Configuration <<" >> ~/.bashrc

Building the Docker image & running the container

Here is a simple approach I use to build the container image and run it:

$ docker build . -t IMAGENAME
$ docker run -dit -v /HOSTDIR:/saga IMAGENAME

In the docker build command, the -t flag tags the image with the name IMAGENAME.

In the docker run command, the -dit flag runs the container in a detached and interactive mode, and the -v flag mounts the host directory /HOSTDIR to the container directory /saga.

To access the container’s shell, get the container’s name CONTAINERID and run the following:

docker exec -it CONTAINERID /bin/bash


As a non-software engineer, it took me a while first to grasp what Docker really is, (e.g., how it differs from virtual machines), what its use cases are, and why another layer of abstraction could be a good thing. But after tinkering with it on a few projects, I have become an enthusiastic user thanks to its portability and replicability. Containerizing legacy code like FORTRAN could be a perfect use case for Docker, so if you haven’t started playing with Docker yet, I encourage you to do so!