Skip to main content

Using containers on M3

What are containers?

For our purposes, a "container" can be defined as a self-contained file system that allows you to run a particular program across multiple operating systems. This allows for more reproducable software and thus reproduceable experiments, though containers can be a little awkward to use. On M3, users are welcome to play with containers for themselves (see our guide below), but the M3 admins often prepare containerised software in the form of modules that are much simpler to use. Please contact our help desk if you'd like to request a particular container to be installed.

Docker

The usage of Docker is unsupported on M3. Fortunately, Apptainer is supported on M3, almost entirely replaces Docker, and is able to work from existing Docker images. The biggest feature provided by Docker that is missing from Apptainer is Docker Compose. You are welcome to try a third-party solution called Singularity Compose for mimicking docker-compose in Apptainer, but we do not provide support for it.

Apptainer

Apptainer (formerly Singularity) simplifies the creation and execution of containers, ensuring software components are encapsulated for portability and reproducibility.

Apptainer is an alternative container solution to Docker that is more compatible with M3. The apptainer command is already installed systemwide, so you don't need to load any modules to use it. See the Apptainer documentation for a user guide.

Building an Apptainer Container

If you to create an Apptainer on M3, note the following:

 sudo apptainer build alpine.sif docker://alpine
  • Unfortunately you can not apptainer build from a definition (.def) file on M3. This requires root privileges. Instead, you would need to build the container somewhere outside of M3, then copy the sif file back to M3.

  • Custom Docker containers can also be built somewhere outside of M3 and converted to .sif files for Apptainer (see Apptainers Documentation ) - this is often preferred since many projects provide Dockerfiles, rather than Apptainer .def files

  • You can convert a Dockerfile to an Apptainer definition file using spython recipe. See https://singularityhub.github.io/singularity-cli/. You will need to install spython for yourself.

note

Please be mindful of your temporary disk storage. Building containers creates large temporary files that could overload the either your $HOME or the server's /tmp folder. Please set the following Bash environment variable to ensure you use a suitable disk.

  • If you are on a login or compute node, please specify the Cache directory with the APPTAINER_CACHEDIR environment variable to be a large folder, i.e. your scratch folder, before running the apptainer pull command. This ensures neither the /tmp nor your your home directory runs out of space. For example, use the following command, replacing <ProjectID> with your project code . e.g.
export APPTAINER_CACHEDIR="$HOME/<ProjectID>_scratch2/${USER}/apptainer-cache
apptainer pull docker://dockername

Note we use the ${USER} variable to make a unique path for you, to avoid the possibility of two users writing to the same cache folder.

Binding Folders

When you run a container yourself, you may need to bind shared file systems into the container with the -B flag. A typical example would be:

apptainer  exec --nv -B /fs04   -B /projects -B /scratch image.sif command.exe

Alternatively you can specify the APPTAINER_BINDPATH as a Bash environment variable.

export APPTAINER_BINDPATH="/fs04,/projects,/scratch,/scratch2"
apptainer exec -nv image.sif command.exe