

Container technologies are widely used for software deployment and reproducibility in scientific computing. Traditional Docker, however, has limitations in High-Performance Computing (HPC) environments. This post looks at why Docker is a poor fit on shared HPC systems and introduces the alternatives commonly used there: Docker rootless, Singularity, and Apptainer.
Docker's security model makes it problematic for shared HPC systems.
Docker requires root privileges to run containers. Docker's daemon operates at the system level and needs elevated permissions to:
On HPC systems with many users sharing resources, giving all users Docker access would create a security problem. A user with Docker access could:
The example below demonstrates how a regular user can escalate to root privileges using Docker:
# A normal user with docker group membershipwhoami# Output: regularuser
# User runs a container and mounts the entire root filesystemdocker run -v /:/host -it ubuntu:latest bash
# Inside the container, the user can access ALL system files as rootroot@container# cat /host/etc/shadow# This reveals root password hashes that should be inaccessible!
root@container# cat /host/root/.ssh/id_rsa# Can steal other users' SSH keys
root@container# whoami# Output: root (inside the container)
# User can write files as rootroot@container# echo "malicious content" > /host/etc/cron.d/backdoorWhat happened here?
/etc/shadow, cron jobs).# Another example: avoiding resource limits# User runs a container with no resource restrictionsdocker run -it --memory=unlimited --cpus=unlimited ubuntu:latest
# Inside the container, a fork bomb can exhaust the node:(){ :|:& };:
# This can crash the entire HPC node, affecting all other usersWhy this is a problem:
# Standard Docker setup (unsafe on shared systems)sudo usermod -aG docker regularuser
# Now regularuser can:docker run -v /:/host ... # Access ANY file on the systemdocker run --privileged ... # Run as rootdocker pull malicious:latest # Download backdoored containersThis is why administrators typically do not grant docker group access on shared HPC systems.
# Typical Docker setup requires sudosudo docker run -it ubuntu:latest bash
# Even with docker group membership, this is a privilege escalation vectordocker run -it ubuntu:latest bashHPC clusters are managed environments with:
Docker's monolithic daemon architecture conflicts with these requirements. Administrators restrict Docker to prevent security breaches and resource conflicts.
Docker rootless allows Docker to run without root privileges, addressing one layer of the privilege escalation problem. It uses user namespaces to isolate the daemon and containers.
Installation:
# Install rootless Dockercurl https://get.docker.com/rootless | sh
# Verify installationdockerd-rootless-setuptool.sh install
# Start the daemonsystemctl --user start dockerUsing rootless Docker:
# No sudo needed!docker run -it ubuntu:latest bash
# Check the userdocker run whoami# Output: root (but it's a mapped non-root user)Docker rootless is a step forward, but it does not resolve the mismatch between Docker's design and HPC requirements.
Singularity was built for HPC environments. It addresses the security and scheduling problems Docker has on clusters. In 2021, it was open-sourced as Apptainer by the Linux Foundation.
User-focused design:
# Run as normal user, no daemon requiredsingularity run mycontainer.sif
# Direct execution without privilege escalationsingularity exec mycontainer.sif python script.pyContainer is a single file:
# Portable and easy to managels -lh mycontainer.sif# Output: -rw-r--r-- 1 user group 2.5G Feb 11 10:00 mycontainer.sif
# Copy between systemscp mycontainer.sif /cluster/home/user/Preserves user identity and permissions:
# Inside container, you're still yourselfsingularity exec mycontainer.sif id# Output: uid=1001(user) gid=1002(group)...
# Access your files as expectedsingularity exec mycontainer.sif ls -la ~Since Singularity/Apptainer are commonly used across HPC systems and bioinformatics workflows, one approach is to install them globally with Pixi, which is often simpler and more reliable than traditional package managers.
Step 1: Install Pixi (if not already installed):
# One-time setupcurl -fsSL https://pixi.sh/install.sh | bash
# Add pixi to your PATH to use in current shell, or open new shell to reloadexport PATH="$HOME/.pixi/bin:$PATH"
# Verify pixi installationpixi --versionStep 2: Install Apptainer globally:
# Simple one-liner - that's it!pixi global install apptainer
# Verify installationapptainer --versionStep 3 (optional): install other common bioinformatics tools globally:
# Install multiple tools at oncepixi global install apptainer -c conda-forge --expose apptainer
# All tools are now available system-wideapptainer --versionBenefits of this approach:
pixi global install apptainerpixi global upgrade apptainerVerify the installation:
# Check versionapptainer --version
# Run a test container from Docker Hubapptainer run docker://ubuntu:22.04 echo "Apptainer works"
# List available sub-commandsapptainer --helpOnce installed globally via Pixi, Apptainer is available to projects and users without activating an environment for each session.
You can build from Docker images or write native definition files.
Method 1: convert a Docker image
# Build directly from Docker Hubapptainer build ubuntu.sif docker://ubuntu:22.04
# Build from existing Docker imageapptainer build myapp.sif docker://myregistry.com/myapp:latestMethod 2: write a definition file
Create myapp.def:
Bootstrap: dockerFrom: ubuntu:22.04
%post apt-get update apt-get install -y python3 pip pip install numpy scipy
%environment export PATH=/usr/local/bin:$PATH
%runscript exec python3 "$@"
%help This container runs Python analysis scriptsBuild it:
# Note: first build may require sudo, but running requires no special privilegesapptainer build myapp.sif myapp.def
# Run without any special privilegesapptainer run myapp.sif script.pyWith Slurm:
#!/bin/bash#SBATCH --job-name=analysis#SBATCH --ntasks=4#SBATCH --mem=16GB#SBATCH --time=01:00:00
# Run container through schedulerapptainer run myapp.sif python /data/analysis.pyWith PBS:
#!/bin/bash#PBS -N analysis#PBS -l select=1:ncpus=4:mem=16gb#PBS -l walltime=01:00:00
cd $PBS_O_WORKDIRapptainer run myapp.sif python /data/analysis.pySingularity does not interfere with scheduler resource allocation; it uses standard system calls.
| Feature | Singularity/Apptainer | Docker | Docker Rootless |
|---|---|---|---|
| No daemon required | Yes | No | No |
| Single file format | Yes | No | No |
| User identity preserved | Yes | No | Partial |
| HPC scheduler integration | Yes | No | No |
| Permission isolation | Yes | Limited | Limited |
| Resource control | Via cgroups | Native | Limited |
| Learning curve | Moderate | Low | Low |
# Requires privileged setupsudo docker run -v /data:/data myapp:latest \ bwa mem reference.fa reads.fastq > output.sam# No sudo, but still not HPC-optimizeddocker run -v /data:/data myapp:latest \ bwa mem reference.fa reads.fastq > output.sam# Simple, no special privileges, works with Slurmsingularity exec myapp.sif \ bwa mem reference.fa reads.fastq > output.sam
# Or in a Slurm scriptsbatch -N 1 --ntasks=8 --mem=32G myjob.sh# (inside myjob.sh runs singularity as normal)# List your imagesdocker images# Convert existing Docker imagesapptainer build myapp.sif docker://myregistry/myapp:latest
# Or build from Docker Compose# First, build your Docker imagedocker build -t myapp:latest .
# Then convertapptainer build myapp.sif docker-daemon://myapp:latest# Run and verifyapptainer run myapp.sif commandapptainer exec myapp.sif python script.py# Copy to clusterscp myapp.sif user@hpc-cluster:/home/user/
# Use in job scriptssbatch my_job.sh| Scenario | Recommendation |
|---|---|
| Local development | Docker or Docker Desktop |
| Single-user HPC access | Singularity/Apptainer |
| Multi-tenant HPC cluster | Singularity/Apptainer |
| Rootless requirement | Docker rootless or Singularity/Apptainer |
| Kubernetes clusters | Docker or similar (not HPC-focused) |
| Maximum compatibility | Singularity/Apptainer |
Docker is well suited to development and cloud infrastructure, but HPC environments call for a different approach. Docker rootless improves Docker's security model but does not resolve HPC integration.
Singularity/Apptainer is a common choice for HPC because it:
On HPC systems, Singularity/Apptainer is the more natural fit. For local development, Docker remains convenient; the image can then be converted to Singularity when deploying to the cluster.





