Run Apptainer on macOS with one command.
Apptainer is Linux-only, so on a Mac it has to run inside a Linux container.
This installer wires up Docker Desktop as that Linux VM and drops a small
apptainer wrapper into ~/.local/bin that transparently runs the official
Apptainer container.
After install you just type apptainer ... like you would on Linux.
- Installs Homebrew if it's missing.
- Installs
qemuandlima(handy if you'd rather run a native Lima VM). - Installs Docker Desktop (the daemon that provides the Linux VM) and starts it.
- Pulls the pinned Apptainer image.
- Installs
bin/apptainerto~/.local/bin/apptainerand adds it to yourPATH.
If apptainer --version already works the script exits immediately.
git clone https://github.com/jonserr/apptainer-macos.git
cd apptainer-macos
./install.shThen open a new terminal (or source ~/.zshrc) and test:
apptainer --versionYou may be asked for your admin password (Homebrew + Docker Desktop first run)
Build a Red Hat / Rocky / Alma image. Example rhel9.def:
Bootstrap: docker
From: rockylinux:9
%post
dnf -y update && dnf -y install gcc make
Then:
apptainer build rhel9.sif rhel9.def
apptainer run rhel9.sifThe Apptainer version is pinned in install.sh:
APPT_VER="1.4.5"Change it and re-run ./install.sh to upgrade. See available tags here.
bin/apptainer is a thin wrapper around:
docker run --rm -it --privileged \
-v /var/run/docker.sock:/var/run/docker.sock \
-v "$PWD":"$PWD" -w "$PWD" \
--entrypoint apptainer \
ghcr.io/apptainer/apptainer:<version> "$@"Mounts your current directory at the same path inside the container so host
paths Apptainer binds resolve correctly, and runs --privileged so image builds
work. The installer copies this template and substitutes the pinned version.