Using Apptainer on Berzelius

Apptainer is an open source container platform designed to be simple, fast, and secure. Apptainer is designed for ease-of-use on shared systems and in high performance computing (HPC) environments.

Please read Apptainer's github page for more information.

Install Apptainer on your local computer

sudo apt-get update
sudo apt-get install -y wget
cd /tmp
wget https://github.com/apptainer/apptainer/releases/download/v1.1.4/apptainer_1.1.4_amd64.deb
sudo apt-get install -y ./apptainer_1.1.4_amd64.deb

Please read Apptainer's documentation for more information.

Build an Apptainer image from scratch

Building an Apptainer image requires root access. You can do it on your local computer.
The created image file can be transferred to Berzelius using scp/rsync command.

sudo apptainer build my_image.sif my_image.def

You can also build an image on Berzelius with a few restrictions using the fakeroot feature. With an interactive session on Berzelius,

apptainer build --fakeroot my_image.sif my_image.def

An Apptainer definition file is a configuration file that provides instructions for building a Apptainer container image. An example of the Apptainer definition file is as follows. Please refer to the Apptainer User Guide for more details.

Bootstrap: docker
From: ubuntu:22.04 

%environment

export PATH="/opt/conda/bin:$PATH"

%post

# Install packages
apt-get update && apt-get install -y --no-install-recommends \
git \
nano \
wget \
curl

# Install Miniconda package manager.
wget -q -P /tmp https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh --no-check-certificate
bash /tmp/Miniconda3-latest-Linux-x86_64.sh -b -p /opt/conda 
rm /tmp/Miniconda3-latest-Linux-x86_64.sh
export PATH="/opt/conda/bin:$PATH"

# Install pytorch
conda install -y pytorch torchvision torchaudio pytorch-cuda=11.7 -c pytorch -c nvidia

Import Apptainer images

You can import an Apptainer image either from Nvidia NGC or Docker Hub repositories. This step can be done either on your local computer or on Berzelius.

  • From Nvidia NGC

    apptainer pull tensorflow-20.03-tf2-py3.sif docker://nvcr.io/nvidia/tensorflow:20.03-tf2-py3

    For other versions, please see the release notes for Pytorch and Tensorflow.

  • From Docker Hub repositories

    apptainer pull pytorch_latest.sif docker://pytorch/pytorch:latest

    For other versions, please see the Docker tags for Pytorch and Tensorflow.

Modify an existing Apptainer image

You can modify an existing image to suit your requirements. You can do it on your local computer.

The modified image file can be transferred to Berzelius using scp/rsync command.

sudo apptainer build --sandbox my_image my_image.sif
sudo apptainer shell --writable my_image/
apptainer my_image/:~> apt-get update
apptainer my_image/:~> apt-get install vim-gtk
apptainer my_image/:~> exit
sudo apptainer build my_image.v2.sif my_image

You can also make the modifications on Berzelius with the fakeroot feature. With an interactive session on Berzelius,

apptainer build --fakeroot --sandbox my_image my_image.sif
apptainer shell --fakeroot --writable my_image/

Start a container

You can start a shell in your container.

apptainer shell --nv -B /local/directory:/data my_image.sif

The flag -B mounts your local directory to your container directory /data. The --nv flag is used run a CUDA application inside a container.

You can also execute the commands or script directly.

apptainer exec --nv -B /local/directory:/data my_image.sif python some_script.py

User Area

User support

Guides, documentation and FAQ.

Getting access

Applying for projects and login accounts.

System status

Everything OK!

No reported problems

Self-service

SUPR
NSC Express