LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

apptainer-build

Build Apptainer container images from definition files or remote sources.

TLDR

Build an image from a definition file
$ apptainer build [path/to/image.sif] [path/to/definition.def]
copy
Convert a registry image straight into a SIF
$ apptainer build [path/to/image.sif] docker://[ubuntu]:[22.04]
copy
Build into a writable sandbox directory, which is easier to iterate on
$ apptainer build --sandbox [path/to/sandbox] docker://[ubuntu]:[22.04]
copy
Turn a finished sandbox back into a SIF
$ apptainer build [path/to/image.sif] [path/to/sandbox]
copy
Build without root, using user namespaces
$ apptainer build --fakeroot [path/to/image.sif] [path/to/definition.def]
copy
Overwrite an image that already exists
$ apptainer build --force [path/to/image.sif] [path/to/definition.def]
copy
Skip the definition's %test section
$ apptainer build --notest [path/to/image.sif] [path/to/definition.def]
copy
Run only some sections of the definition
$ apptainer build --section [post] [path/to/image.sif] [path/to/definition.def]
copy
Pass a build argument into the definition
$ apptainer build --build-arg [VERSION]=[1.2] [path/to/image.sif] [path/to/definition.def]
copy
Ignore the local cache
$ apptainer build --disable-cache [path/to/image.sif] docker://[image]:[tag]
copy
Build for a different architecture
$ apptainer build --arch [arm64] [path/to/image.sif] [path/to/definition.def]
copy
Produce an encrypted image
$ apptainer build --encrypt --pem-path [path/to/key.pem] [path/to/image.sif] [path/to/definition.def]
copy

SYNOPSIS

apptainer build [options] image build-spec

DESCRIPTION

apptainer build creates Apptainer container images from various sources including definition files, Docker Hub, OCI registries, and the Sylabs Container Library. The resulting SIF (Singularity Image Format) file is a portable, immutable container image.Definition files (.def) provide a reproducible way to specify base images, software installation steps, environment variables, and runscripts. The sandbox mode creates a writable directory structure useful for development and testing.

PARAMETERS

-s, --sandbox

Build a writable directory instead of an immutable SIF image
-F, --force
Overwrite an existing image file without prompting
-f, --fakeroot
Build using fakeroot, appearing to run as root (default for unprivileged definition builds).
--disable-cache
Do not use or create cached images during the build process.
--no-cleanup
Retain the temporary build directory after a failed build (for debugging).
-u, --update
Run the definition over an existing sandbox container, rerunning sections such as %post.
-T, --notest
Build the container without running the %test section.
--section name
Run only the given definition sections instead of all of them (e.g. post, environment).
-e, --encrypt
Build an image with an encrypted filesystem (set APPTAINERENCRYPTIONPASSPHRASE or APPTAINERENCRYPTIONPEM_PATH).
--build-arg key=value
Replace {{ key }} placeholders in the definition file with the given value.
--arch arch
Architecture to build for (default: amd64).

CONFIGURATION

/etc/apptainer/apptainer.conf

Main configuration file controlling build behavior, security settings, bind paths, and fakeroot mappings.

INSTALL

sudo dnf install apptainer
copy
sudo pacman -S apptainer
copy
sudo apk add apptainer
copy
sudo zypper install apptainer
copy
brew install apptainer
copy
nix profile install nixpkgs#apptainer
copy

CAVEATS

Building containers often requires elevated privileges or fakeroot configuration. Some base images may not be compatible with fakeroot builds. Large builds can consume significant disk space in the cache directory.

SEE ALSO

RESOURCES

Braincup
Open source brain training for math, memory and focus
Braincup mini-games
41 mini-games · Apache-2.0
No ads · No tracking
Play in browser
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid
276 stars
From the maker of Linux Command Library
Copied to clipboard
Braincup
Open source brain training for math, memory and focus. 41 mini-games, from mental arithmetic to Sudoku, N-Back and Solo Chess.
Apache-2.0 licensed · No ads · No tracking · No account
From the maker of Linux Command Library
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid