Skip to content

Containers on Slurm

Exercises

  1. Pull and inspect a container

Pull a container image from a public registry and examine its metadata. Use an image relevant to your work, or try the official Ubuntu image as a simple test. Inspect the image to see its labels, environment, and runscript.

Hint / Solution
# Load apptainer via Lmod (the canonical HPC pattern — the
# binary lives on a shared filesystem so the same install is
# reachable from head and compute nodes).
module load apptainer/1.5.4

# Pull an image (converts to SIF format). The ECR public mirror
# is more reliable than Docker Hub for automated runs; `--force`
# lets you re-pull over an existing ubuntu.sif.
apptainer pull --force ubuntu.sif docker://public.ecr.aws/docker/library/ubuntu:latest

# Inspect the image metadata
apptainer inspect ubuntu.sif

# See the image's default runscript
apptainer inspect --runscript ubuntu.sif

# See the image's environment setup
apptainer inspect --environment ubuntu.sif

# Quick test -- run a command inside the container
apptainer exec ubuntu.sif cat /etc/os-release
Expected output: Validated 2026-10-19 on slurm-training-val (Slurm 25.11.8, ParallelCluster 3.16.1).
$ module load apptainer/1.5.4 && apptainer --version
apptainer version 1.5.4

$ module load apptainer/1.5.4 && apptainer pull --force ubuntu.sif docker://public.ecr.aws/docker/library/ubuntu:latest 2>&1
INFO:    Using cached SIF image

$ module load apptainer/1.5.4 && apptainer exec ubuntu.sif cat /etc/os-release
INFO:    squashfuse not found, will not be able to mount SIF or other squashfs files
INFO:    gocryptfs not found, will not be able to use gocryptfs
INFO:    Converting SIF file to temporary sandbox...
PRETTY_NAME="Ubuntu 26.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="26.04"
VERSION="26.04.1 LTS (Resolute Raccoon)"
VERSION_CODENAME=resolute
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=resolute
LOGO=ubuntu-logo
INFO:    Cleaning up image...
  1. Run a containerized job

Write a Slurm batch script that runs a command inside a container. Use --bind to mount a data directory from the host into the container. Verify that the job can read input data and write output back to the host filesystem.

Hint / Solution
# Create test input data
mkdir -p /shared/$USER/container_test/input
mkdir -p /shared/$USER/container_test/output
echo "Hello from the host" > /shared/$USER/container_test/input/data.txt

# Write the job script — note the `module load apptainer` line:
# batch jobs run on compute nodes which don't have apptainer on
# PATH by default. Loading the module brings it onto PATH from
# the shared install.
cat > container_job.sh << 'EOF'
#!/bin/bash
#SBATCH --job-name=container_test
#SBATCH --output=container_%j.out
#SBATCH --time=00:10:00
#SBATCH --ntasks=1
#SBATCH --mem=2G

module load apptainer/1.5.4

DATADIR=/shared/$USER/container_test

apptainer exec \
  --bind $DATADIR/input:/mnt/input \
  --bind $DATADIR/output:/mnt/output \
  ubuntu.sif \
  bash -c "cat /mnt/input/data.txt && echo 'Processed at $(date)' > /mnt/output/result.txt"

echo "Job finished. Output:"
cat $DATADIR/output/result.txt
EOF

# Submit
sbatch container_job.sh
After the job completes, check `container_.out` for the output and verify that `/shared/$USER/container_test/output/result.txt` was written. Expected output: Validated 2026-10-19 on slurm-training-val (Slurm 25.11.8, ParallelCluster 3.16.1).
$ sbatch container_job.sh
Submitted batch job 42

References