Rivet tutorials

Running Rivet through Apptainer

Background: why Apptainer and not Docker?

Rivet is distributed as a ready-made software image – a self-contained bundle with all its dependencies baked in, so you don’t have to install anything yourself. On your laptop you’d typically run that image with Docker.

On shared computing clusters, Docker isn’t usually available: it needs a privileged background service (the “Docker daemon”) running as root, which is a security headache on a multi-user system. Instead, clusters often provide Apptainer (formerly Singularity), a container runtime designed for HPC. The good news is that Apptainer can pull and run Docker images directly, so you can use exactly the same image – you just drive it with slightly different commands.

If you’ve used Docker before, the table at the end maps the commands across. If you haven’t, don’t worry: just follow the steps in order.

One-time setup

The first time Apptainer runs a Docker image, it downloads it and converts it into its own format (a single .sif file). This conversion uses a cache directory that lives in your home directory by default – and on the cluster, home directories have a small quota that container images will fill up very quickly.

So before anything else, tell Apptainer to use a scratch area or similar, e.g. by adding these lines to your ~/.bashrc:

export APPTAINER_CACHEDIR=/path/to/apptainer/area/.apptainer
export APPTAINER_TMPDIR=/path/to/apptainer/area/tmp

Then create the directories and reload your shell:

mkdir -p /path/to/apptainer/area/.apptainer /path/to/apptainer/area/tmp
source ~/.bashrc

You only need to do this once.

Running the Rivet container

From the directory containing your work area (or wherever you’d like your output to land), run:

apptainer shell --pwd /work --cleanenv --no-home -B $PWD:/host docker://hepstore/rivet

This drops you into an interactive shell inside the container, in the /work directory, with Rivet ready to use. To leave the container, type exit or press Ctrl-D.

What each part does

| Part | What it does | |------|--------------| | apptainer shell | Start an interactive shell inside the container. | | --pwd /work | Start in the /work directory, where Docker would also drop you inside the image. | | --cleanenv | Start with a clean set of environment variables, so settings from your own account don’t leak in and clash with the container’s. | | --no-home | Don’t mount your home directory into the container. This keeps things isolated and avoids e.g. your personal Python setup interfering with the image’s. | | -B $PWD:/host | “Bind mount” your current directory into the container at /host, so you can read and write your own files from inside. (-B is short for --bind.) | | docker://hepstore/rivet | The image to run. The docker:// prefix tells Apptainer to fetch it from Docker Hub. |

The key idea is the split between two directories:

So a good habit is to keep your own analysis files and outputs under /host.

Faster repeat runs: pull a local image

The command above re-checks the image every time. If you’re going to use it repeatedly, it’s quicker to download it once into a local .sif file and run that:

# Download and convert once
apptainer pull rivet.sif docker://hepstore/rivet

# Run it (note: local file, no docker:// prefix)
apptainer shell --pwd /work --cleanenv --no-home -B $PWD:/host rivet.sif

The rivet.sif file is just a normal file — you can keep it in your preferred work space and reuse it across sessions.

Running a command without an interactive shell

apptainer shell is ideal for working inside the container. If instead you want to run a single command (for example inside a batch job script), use apptainer exec:

apptainer exec --cleanenv --no-home -B $PWD:/host rivet.sif rivet --version

Here everything after the image name is the command to run inside the container.

Common problems

“I can’t see my files.” Your files are under /host, not /work. Run ls /host to find them. If you want to copy something from the container into your own space, cp /work/somefile /host/.

“My changes disappeared when I exited.” The container’s own filesystem is read-only and temporary — only things written under /host (your real directory) survive. Make sure your outputs go there.

Home quota errors when pulling. This almost always means the cache setup above hasn’t taken effect. Check with echo $APPTAINER_CACHEDIR — it should print the path to your designated apptainer area, not something under /home.

--pwd doesn’t seem to work. On older Apptainer/Singularity versions this flag occasionally misbehaves. As a fallback, just run cd /work once you’re inside the shell.

Quick reference: Docker → Apptainer

If you’ve used the Docker version of the tutorial, here’s the translation:

# Docker (e.g. on your laptop)
docker run -it --rm -v $PWD:/work hepstore/rivet

# Apptainer (on the cluster)
apptainer shell --pwd /work --cleanenv --no-home -B $PWD:/host docker://hepstore/rivet

| Docker | Apptainer | Notes | |--------|-----------|-------| | docker run | apptainer shell / run / exec | shell for interactive use. | | -it | (not needed) | apptainer shell is interactive by default. | | --rm | (not needed) | Nothing persistent is created to clean up. | | -v src:dest | -B src:dest | Same source:destination syntax. | | image | docker://image | The docker:// prefix pulls from Docker Hub. | | WORKDIR (from image) | --pwd /work | Apptainer ignores the image’s working directory, so set it explicitly. |