1.6. Use SPEX through Docker

SPEX is written mostly in Fortran 90 and depends on a few system libraries. This makes it difficult to provide a few binary versions that will continue to run on multiple platforms over many years. Therefore, we have also created a Docker image for SPEX that can be run on the Docker platform, which is available for Linux, Mac OS and Windows.

1.6.1. Step 1: Download and install Docker on your computer

To run a Docker image, please install Docker on your computer. See the Docker website for details and look for the Docker Engine community edition. Once you have downloaded and installed Docker, you can continue with this tutorial.

1.6.2. Step 2: Download the SPEX docker image from Zenodo

The SPEX Docker image is available on this Zenodo page as a tar.gz file. Please download the file called spex-[version]-Docker.tar.gz, for example:

spex-3.06.01-Docker.tar.gz

Or, alternatively, you can pull the image from Docker hub with the command: docker pull spexxray/spex:latest.

1.6.3. Step 3: Import the SPEX image into Docker

Before you can run the docker file, it should be imported into the docker system. This can be done on the command line:

user@linux:~> docker load -i spex-3.06.01-docker.tar.gz

The image will be named spexxray/spex with the tag 3.05.00 and can be found with the command:

user@linux:~> docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
spexxray/spex 3.06.01 0a0a0a0a0a0 1 minute ago 996MB

1.6.4. Step 4: Run SPEX on Docker

Using the docker run command, the image can be executed and SPEX can be run in a so-called container. To enjoy all the capabilities of SPEX, two things need to be arranged in the docker run command: access to local directories and a graphical X11 connection. To arrange this, additional flags need to be specified on the command line.

1.6.5. Mounting local directories to the container

If you would like to mount your own home directory into the SPEX container such that you can use some spo and res files there or save the output files, then you need the following flags:

-e LOCAL_USER_ID=`id -u $USER`
-v /home/myusername:/home/user

The first flag arranges that the user in the container will have the same user ID as you. This will allow you to read and write to your home directory from within the container.

The second flag arranges that your true local home directory called /home/myusername is mounted to /home/user inside the SPEX container.

MAC users: Please note that on OSX your home directory is in /Users/myusername.

1.6.6. Arranging the X11 connection

To make sure PGPLOT can connect to the X11 server on the host, we need to make a few connections from the container to the host machine. This is done with the following flags:

-e DISPLAY=$DISPLAY
-v /tmp/.X11-unix:/tmp/.X11-unix

The first flag sets the DISPLAY variable inside the container to the DISPLAY variable of the host machine. The second flag mounts the X11 temporary directory of the host to the same directory inside the container.

MAC users: To use X11 on Mac, you need to install XQuartz (or a similar X11 server) and set it to ‘Allow connections from network clients’ in the XQuartz settings. In addition, the X server should be set to allow incoming connections from localhost on the command line:

user@macos:~> xhost +127.0.0.1

Then the DISPLAY variable on the docker run line should be set to host.docker.internal:0

1.6.7. The complete docker run command

The full run commands for docker now look like below, where -w means that the container will start in working directory /home/user.

For Linux:

docker run -it \
-e DISPLAY=$DISPLAY \
-e LOCAL_USER_ID=`id -u $USER` \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-v /home/myusername:/home/user \
-w /home/user \
spexxray/spex:3.06.01

For Mac:

docker run -it \
-e DISPLAY=host.docker.internal:0 \
-e LOCAL_USER_ID=`id -u $USER` \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-v /Users/myusername:/home/user \
-w /home/user \
spexxray/spex:3.06.01

The docker run command above will provide you with a prompt that will allow you to run spex:

user@linux:~> docker run -it -e DISPLAY=$DISPLAY -e LOCAL_USER_ID=`id -u $USER` \
-v /tmp/.X11-unix:/tmp/.X11-unix -v /home/myusername:/home/user -w /home/user \
spexxray/spex:3.06.01

Welcome to the SPEX Docker Container!
Just type 'spex' to start the program.
user@0922f2e4ff85:~>

In this environment, you can just run spex or trafo:

user@0922f2e4ff85:~> spex
 Welcome user to SPEX version 3.06.01

 NEW in this version of SPEX:
22-07-2020 Bugfix: neij gives line emission while abundance is zero.
18-08-2020 Changed reference density from electron density to hydrogen density.
04-09-2020 Added pyroxene back to the amol model.
23-10-2020 Update of H I collision strengths (IMPORTANT)
24-11-2020 Added ascdump and par_show functions for the Python interface.

 Currently using SPEXACT version 2.07.00. Type `help var calc` for details.

SPEX>