Skip to content

6. How to build a container with apptainer build --force --fakerootΒΆ

Although BMRC does not have a dedicated sandbox to build containers at the moment, fakeroot is enabled in both the login nodes and compute nodes allowing researchers to build containers as needed

Build a container on a BMRC login node

  • To illustrate this functionality, create an example container definition file my_container.def from a shell session on NeSI as follows:
cat << EOF > my_container.def
BootStrap: docker
From: ubuntu:20.04
%post
    apt-get -y update
    apt-get install -y wget
EOF
  • Build command follows the format of apptainer build --force --fakeroot NAME_OF_THE_CONTAINER_AFTER_THE_BUILD.aif name_of_the.def
  • If you have $APPTAINER_BIND set globally, unset it with unset APPTAINER_BIND for apptainer build commands. Otherwise the build commands will fail as bind mounts set via this environment variable are NOT supported during build operations
    • The build process executes in a special, isolated environment and does NOT honor the APPTAINER_BIND or APPTAINER_BINDPATH environment variables.
    • Only directories specified with the --bind argument are recognized and mounted during the build's %post or %test sections, if the destination mount points already exist in the bootstrap image
unset APPTAINER_BIND

apptainer build --force --fakeroot my_container.aif my_container.def

Build a container on BMRC via Slurm job

  • Since some container builds can consume a significant amount of CPUs and memory, our recommendation is to perform these builds via a Slurm job (either interactive or batch queue). Unfortunately, BMRC compute nodes do not have www access by default. Please contact the KIR Research Computing Manager for assistance configuring your environment to allow compute nodes www access.