Why you should use Apptainer
A simple discussion assuming minimal background of why to use Apptainer or Singularity and how it is different than Docker.
Apptainer provides containerized environments. A commonly referenced example is Docker which is also container software. throughout this intro, I will continue with assuming you don’t know much about Docker but since it is the primary alternative, I will mention it quite a bit.
How is a container different than an OS or VM?
You know operating systems (Linux, Mac, Windows)? And you know you can install each as a virtual machine? Also, you know that you can install software on the OS and on the VM but they are virtually separated?
Well, a container is like that. It is a packaged operating system with software installed that is “isolated” from your main OS. Commonly VMs are complained about for running slow and they do because it is a complete duplicate of everything running on a virtual computer with dedicated resources (RAM, CPU cores, HDD) that are less than your base system. Containers differ here because they only run the subset of the system that you need, which usually means not nearly as many processes or a GUI (think of a headless OS). Also, there is less of a bottleneck because you don’t dedicate resources to it, instead, they are dynamically shared with your OS. So if your container is using a lot of computation cycles while your OS is idling, it can take more.
Why would I use a container at all?
- Perhaps you are a user of ROS (Robot Operating System) and you need a specific version of Ubuntu to run your code inside of.
- Maybe you need multiple Linux types and releases to test your code against.
- Possibly you are working with a team of people, each with different OS versions and different software configurations.
All of the above reasons and many more are great benefits of a container (and this goes for just about any container type). You often want to take your existing system (say Ubuntu 20.04) and just run software that relies on Ubuntu 15.10 or CentOS or Alpine without having to have each installed. You want to be able to enter and exit these alternative environments with ease, not needing a reboot or to wait on a VM and deal with updating each. Lets say you want to test your software on 3 different Linux distributions and the last 4 version releases of each. That quickly becomes 12 different operating systems to keep track of. I don’t know about you, but its easy to get confused and overwrite your data when dual-booting just 2 operating systems.
What is special about Apptainer?
Apptainer was designed to be installed by someone with root (also a requirement of Docker & VMs) but then executed by someone without root. Note that this is something you cannot do with Docker. This allows for regular users of a shared system to run the software they like. Let me walk you through the most basic and common user workflow:
1. Build on personal computer (requires root)
2. Move to shared system
3. Execute on shared system (without root)
This feature alone allows Apptainer to have many use cases that don’t exist for Docker, especially in research HPC (High-Performance Computer) environments. Some other defaults of Apptainer also make it be great for these use cases. Here are some of the highlights:
- Defaults to running as the current user
- Defaults to mounting the home directory in /home/$USER
- Defaults to running as a program (not background process)
Now, each of these can actually be accomplished with Docker. Similarly, Apptainer can be configured to not run with these defaults though they are quite beneficial. Let me address each individually:
1st: If you have ever created a file inside of Docker and then attempted to delete it outside, you will likely get permission errors as the file will have been created as root and a local user would not have edit permissions.
2nd: Just to manipulate data on your system in Docker, you would need to pass in command-line arguments to mount the home directory and this requires remembering the syntax and performing it would vary per user. With Apptainer, the home folder mounts by default allowing easy read and write of information, especially since it is being run as the current user as well.
3rd: When launching Docker, by default you will see a few startup messages and then it will disappear to the background. In Apptainer the container runs much like running a program and it will stay active in the terminal unless you specifically send it to the background. Now if you are trying to run a web server all day, you can use the instance feature which accomplishes the same as Docker.
Why use Docker?
I will be honest, I am by no means a docker expert. But based on what I have shared so far, you may be asking why Docker is used at all.
Well, Docker does have a much larger following with 3rd party applications historically supporting it first. Most images I build my containers from are actually based on Docker images because their Docker hub is just plainly superior at the time.
Also, Docker uses image layering which allows minimizing size on disk. Consider this example: You are making cupcakes, 1 will be just the base with no frosting, 1 will have frosting, and 1 will have frosting and sprinkles. If you consider the bread, frosting, and sprinkles as each a separate layer, the final recipes will share the same base layers and not use additional disk space. Apptainer does not do this.
Do I expect this to change? Perhaps down the road, Apptainer will grow in stature as it has just gained the support of the Linux Foundation and several big-name firms like AMD & Intel endorsing this growth, you can read about that below.
New Linux Foundation Project Accelerates Collaboration on Container Systems Between Enterprise and…
Apptainer was created to run complex applications on HPC clusters in a simple, portable, and reproducible way. First…
How to get started with Apptainer?
Check out some of my existing tutorials and future ones to come. Specifically, I explain how to install it here:
Setting up Apptainer to Make Container Environments
Be able to build modular contained environments in Apptainer, the next generation of Singularity.
You can also check out the Github repository here:
GitHub - apptainer/apptainer: Apptainer: Application containers for Linux
NOTE: The apptainer repo is currently up to a v1.0.0 release candidate and not ready for production in its current…
If you have heard of similar software such as Singularity, then you are in good hands. Apptainer is actually just the next generation of Singularity as it received support from the Linux Foundation. The creator of Singularity is leading the charge with Apptainer and the repository is forked from Singularity. For now (not officially supported so YMMV) you can run Apptainer and Singularity containers interchangeably.
If you liked this article, give me a follow and stay tuned!