What Is Apptainer and How Do You Install It on Ubuntu Server?

The Apptainer/Singularity package has become one of the most widely-used container deployment systems for High-Performance Computing (HPC). This container system is designed to execute applications with bare-metal performance while retaining a high level of security, portability, and reproducibility.
Apptainer is an open source project with a growing community and ever-expanding user base. The feature set looks something like this:
- Supports public/private key signing for trust.
- Compatibility with Docker and the Open Containers Initiative.
- Encryption.
- Portability.
- Containers run rootless to prohibit privilege escalation.
- Leverages GPUs, FPGAs, high-speed networks, and filesystems.
- Easy to use.
- Commerical support available.
Although Apptainer isn’t nearly as easy to install as, say, Docker, if you’re looking for higher security in your containers, this might just be the deployment system you’re looking for.
But just how is it installed? That’s what I want to show you now.
Requirements
Apptainer can be installed on both RHEL and Ubuntu-based Linux distributions. I’ll demonstrate with my go-to server, Ubuntu Server 22.04, so you’ll need a running instance of that OS and a user with sudo privileges. That’s it… let’s get this party started.
Installing the Necessary Dependencies
The first thing to be done is the installation of the necessary dependencies. Log in to your Ubuntu instance and issue the command:
1 2 3 4 5 6 7 8 9 10 11 12 |
sudo apt-get install -y \ build-essential \ libseccomp-dev \ pkg-config \ uidmap \ squashfs-tools \ squashfuse \ fuse2fs \ fuse-overlayfs \ fakeroot \ cryptsetup \ curl wget git |
For those of you who might be new to Linux, the above is a single command broken into steps using the \ character. The single-line version of that command looks like this:
1 2 |
sudo apt-get install build-essential libseccomp-dev pkg-config uidmap squashfs-tools \n squashfuse fuse2fs fuse-overlayfs fakeroot cryptsetup curl wget git -y |
Do note, if you are using a RHEL-based distribution, the installation of the dependencies is a bit more complicated. First, you must install the Development Tools with:
1 |
sudo yum groupinstall -y 'Development Tools' |
Next, add the EPEL repository:
1 |
sudo yum install -y epel-release |
Finally, you can install the dependencies with:
1 2 3 4 5 6 7 8 9 |
sudo yum install -y \ libseccomp-devel \ squashfs-tools \ squashfuse \ fuse-overlayfs \ fakeroot \ /usr/*bin/fuse2fs \ cryptsetup \ wget git |
Next, we must install Go. First, set the version and the architecture with:
1 |
export GOVERSION=1.19.1 OS=linux ARCH=amd64 |
Download the necessary file with:
1 2 |
wget -O /tmp/go${GOVERSION}.${OS}-${ARCH}.tar.gz \n https://dl.google.com/go/go${GOVERSION}.${OS}-${ARCH}.tar.gz |
Unpack and move the downloaded file with:
1 |
sudo tar -C /usr/local -xzf /tmp/go${GOVERSION}.${OS}-${ARCH}.tar.gz |
Add the Go executable to your user’s PATH with the following two commands:
1 2 |
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc source ~/.bashrc |
We now need to install the golangcli-lint tool with:
1 2 |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh \n | sh -s -- -b $(go env GOPATH)/bin v1.43.0 |
Add this to your PATH with:
1 2 |
echo 'export PATH=$PATH:$(go env GOPATH)/bin' >> ~/.bashrc source ~/.bashrc |
Clone the Apptainer Repo and Install
With the dependencies out of the way, we can now clone the Apptainer repository and install the software.
Clone the repository with:
1 |
git clone https://github.com/apptainer/apptainer.git |
Change into the newly created directory with:
1 |
cd apptainer |
Check out the latest version with:
1 |
git checkout v1.1.0-rc.3 |
Make sure to check out the releases page to ensure you’re using the latest version.
Run the configuration script with the command:
1 |
./mconfig |
Change into the build directory:
1 |
cd ./builddir |
Compile Apptainer with the following command:
1 |
make |
The above command will take considerable time to complete (upwards of 10 minutes). At some point, you may think it has stalled. Don’t panic! Keep your fingers away from the [Ctrl]+[C] keyboard shortcut and allow the installation to complete.
Once the make command completes, install Apptainer with:
1 |
sudo make install |
When the install process finishes, you can verify everything went as planned by viewing the Apptainer version with the command:
1 |
apptainer --version |
You should see something like the following in the output:
1 |
apptainer version 1.1.0-rc.3 |
Outstanding. Apptainer is installed and ready for action.
How to Deploy a Container with Apptainer
Let’s now deploy the always fun Hello World container with Apptainer. To do this, we’ll pull down the hello-world app from the Singularity hub with the command:
1 |
singularity pull shub://singularityhub/hello-world |
You should then see a new file in that directory, named:
1 |
hello-world_latest.sif |
To run the app, issue the command:
1 |
./hello-world_latest.sif |
The app will then print out:
1 |
Tacotacotaco |
You could also run the container with:
1 |
apptainer run hello-world_latest.sif |
Let’s say you want to use Ubuntu 20.04 as a container. You could pull it with:
1 |
apptainer pull docker://ubuntu:latest |
Once it’s pulled you can run a command from within the container with something like this:
1 |
apptainer exec ubuntu_latest.sif cat /etc/os-release |
You should see the following in the output:
1 2 3 4 5 6 7 8 9 10 11 12 |
NAME="Ubuntu" VERSION="20.04.5 LTS (Focal Fossa)" ID=ubuntu ID_LIKE=debian PRETTY_NAME="Ubuntu 20.04.5 LTS" VERSION_ID="20.04" HOME_URL="https://www.ubuntu.com/" SUPPORT_URL="https://help.ubuntu.com/" BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/" PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy" VERSION_CODENAME=focal UBUNTU_CODENAME=focal |
And that’s all how you get started with the Apptainer container deployment system. This is a great option for any container admin looking to get a bit more security from their deployments.