<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="../assets/xml/rss.xsl" media="all"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"><channel><title>civilfritz.net (Posts about apptainer)</title><link>https://civilfritz.net/</link><description></description><atom:link href="https://civilfritz.net/tags/apptainer.xml" rel="self" type="application/rss+xml"></atom:link><language>en</language><copyright>Contents © 2026 Jonathon Anderson, licensed CC BY-SA 4.0</copyright><lastBuildDate>Thu, 26 Nov 2026 15:52:54 GMT</lastBuildDate><generator>Nikola (getnikola.com)</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>Benchmarking Containerized MPI with Apptainer on Dell PowerEdge and Cornelis Omni-Path</title><link>https://civilfritz.net/posts/benchmarking-containerized-mpi-with-apptainer-on-dell-poweredge-and-cornelis-omni-path/</link><dc:creator>Jonathon Anderson</dc:creator><description>&lt;p&gt;&lt;a class="reference external" href="https://ciq.com/blog/benchmarking-containerized-mpi-with-apptainer-on-dell-poweredge-and-cornelis-omni-path"&gt;This article was also published via the CIQ blog on 6 September 2023.&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a class="reference external" href="https://ciq.com/blog/deploying-a-dell-poweredge-and-cornelis-omni-path-cluster-with-warewulf"&gt;In a previous
article&lt;/a&gt;,
I demonstrated how Warewulf makes it simple to deploy an HPC cluster.
Now, I don’t know about you; but, once I have a cluster, I immediately
start looking for something to run on it. But I’m a systems guy—not a
domain scientist—so that usually means I start benchmarking.&lt;/p&gt;
&lt;p&gt;Recently at CIQ, we’ve been advocating for attention and development
around containerization of MPI using Apptainer. In particular, we’ve
been championing the use of
&lt;a class="reference external" href="https://www.mcs.anl.gov/papers/P1760.pdf"&gt;PMI&lt;/a&gt; to support completely
portable MPI containerization, where the containerized application
shares no MPI dependency with the host system. It’s our hope that, by
making containerized MPI more portable and more broadly applicable,
we’ll see even broader adoption of containerization in HPC.&lt;/p&gt;
&lt;p&gt;But this increased adoption brings stronger questions about performance:
do containerized MPI applications perform as well as the same
applications running directly in the host environment?&lt;/p&gt;
&lt;section id="so-what-are-we-doing-here"&gt;
&lt;h2&gt;So what are we doing here?&lt;/h2&gt;
&lt;p&gt;My focus here is on MPI performance, not necessarily CPU or memory
performance. With that in mind, I selected the &lt;a class="reference external" href="https://mvapich.cse.ohio-state.edu/benchmarks/"&gt;OSU
Micro-Benchmarks&lt;/a&gt;
suite for my test cases. In particular, I used &lt;code class="docutils literal"&gt;osu_bw&lt;/code&gt;, &lt;code class="docutils literal"&gt;osu_bibw&lt;/code&gt;,
and &lt;code class="docutils literal"&gt;osu_alltoall&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;As I started to run benchmarks and follow my curiosity, the number of
test cases grew: originally, this was just supposed to be a simple
demonstration at the end of the previous article! But to keep even this
separate writeup to a reasonable scope, I focused on these questions:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;p&gt;Does performance differ between the host Rocky Linux 8 environment and
a container?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Does performance change if a Rocky Linux 9 container runs on a Rocky
Linux 8 host?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Does performance differ between Apptainer containers with “user
namespaces” compared to Apptainer running with its original SUID
starter?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Does behavior change when running tasks across nodes vs. all on a
single node?&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/section&gt;
&lt;section id="benchmark-environment"&gt;
&lt;h2&gt;Benchmark environment&lt;/h2&gt;
&lt;p&gt;To review: we’ve got a cluster of four compute nodes in a Dell PowerEdge
C6525 multi-node server. Each node is equipped with 2x AMD EPYC 7702
CPUs, 256GiB system memory, and a 100Gb Cornelis Omni-Path HFI. All four
nodes are connected to a single Cornelis Omni-Path switch.&lt;/p&gt;
&lt;p&gt;To maintain consistency between the host and container environments, I
used &lt;a class="reference external" href="https://spack.io"&gt;Spack&lt;/a&gt; v0.20.1 to build nine different
versions of OSU Micro-Benchmarks, with variants for MPI
(&lt;a class="reference external" href="https://www.mpich.org"&gt;MPICH&lt;/a&gt;,
&lt;a class="reference external" href="https://mvapich.cse.ohio-state.edu"&gt;MVAPICH&lt;/a&gt;, and &lt;a class="reference external" href="https://www.open-mpi.org/"&gt;Open
MPI&lt;/a&gt;) and operating environment (the
compute node’s Rocky Linux 8.8 environment, a Rocky Linux 8.8 SIF, and a
Rocky Linux 9.2 SIF). I used Spack’s built-in
&lt;a class="reference external" href="https://spack.readthedocs.io/en/v0.20.0/containers.html"&gt;“containerize”&lt;/a&gt;
functionality to build the SIFs. The Spack “specs” for each build, and
the Spack environment YAML files used for &lt;code class="docutils literal"&gt;spack containerize&lt;/code&gt;, are
included as attachments.&lt;/p&gt;
&lt;p&gt;All tests were run on the same host kernel,
&lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;4.18.0-477.15.1.el8_8.x86_64&lt;/span&gt;&lt;/code&gt;, and all container tests used Apptainer
version &lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;1.2.2-1.el8&lt;/span&gt;&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;All tests were run with the same Slurm arguments, including an explicit
&lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;--nodelist&lt;/span&gt;&lt;/code&gt; argument to ensure that all tests were run on the same
nodes. These complete commands are included in an attachment.&lt;/p&gt;
&lt;p&gt;All three MPI implementations were built using libfabric which, in turn,
was built with support for
&lt;a class="reference external" href="https://www.openfabrics.org/wp-content/uploads/2022-workshop/2022-workshop-presentations/106_TThompson.pdf"&gt;OPX&lt;/a&gt;,
the latest and recommended libfabric provider for use with Cornelis
Omni-Path. We were able to verify that OPX was being properly detected
and activated using logging capabilities of libfabric common to all of
our builds, and these records are attached as well.&lt;/p&gt;
&lt;/section&gt;
&lt;section id="does-performance-differ-between-the-host-and-a-container"&gt;
&lt;h2&gt;Does performance differ between the host and a container?&lt;/h2&gt;
&lt;p&gt;Our first question is the simplest: does containerization with Apptainer
reduce the MPI performance of an application? From our experience here,
we can say that it does not. In fact, we saw somewhat &lt;em&gt;improved&lt;/em&gt;
latencies for &lt;code class="docutils literal"&gt;osu_alltoall&lt;/code&gt; in containerized environments, and any
bandwidth performance differences were within general run-to-run
variance. In fact, some of our &lt;em&gt;highest&lt;/em&gt; performance differences were
observed simply from rebooting compute nodes and re-running the same
test.&lt;/p&gt;
&lt;p&gt;Raw results for these and other tests are included as attached CSV files
at the end of the article.&lt;/p&gt;
&lt;/section&gt;
&lt;section id="does-performance-change-for-a-rocky-linux-9-container"&gt;
&lt;h2&gt;Does performance change for a Rocky Linux 9 container?&lt;/h2&gt;
&lt;p&gt;Containerization isn’t just about running an application in an identical
operating environment to the compute node host: it enables the
flexibility to run different versions of an operating system, or even
entirely different operating systems, within the container. So what if
we run a different version of Rocky Linux–9.2, in our tests
here–compared to the Rocky Linux 8.8 that is running on the compute
node?&lt;/p&gt;
&lt;p&gt;The question isn’t entirely unfounded: Cornelis Omni-Path support, for
example, is built on a mixture of kernel and user-space components. For
our tests, we’re using the support for OPA included in the Rocky Linux
kernel, and each version of Rocky Linux includes user-space libraries
and applications designed to work with its matching kernel components.
The nature of containerization, however, implies that we’re using the
kernel components from the host, regardless of what user-space code is
running in the container. So what happens if we run an MPI built for a
Rocky Linux 9.2 environment on a Rocky Linux 8.8 kernel?&lt;/p&gt;
&lt;p&gt;While we obviously can’t speak for all kernel and user-space pairings,
our results indicate that even this difference isn’t something to worry
about. Most results were within run-to-run variance, with yet another
apparent &lt;em&gt;improvement&lt;/em&gt; in &lt;code class="docutils literal"&gt;osu_alltoall&lt;/code&gt; latency. (This improvement
probably shouldn’t carry too much weight, however, given the limitations
of our testing methodology; but we’ll talk more about that in the
conclusion.)&lt;/p&gt;
&lt;/section&gt;
&lt;section id="does-performance-differ-for-apptainer-suid-and-user-namespace-modes"&gt;
&lt;h2&gt;Does performance differ for Apptainer SUID and user namespace modes?&lt;/h2&gt;
&lt;p&gt;If you’ve been following Apptainer development, one of its more recent
improvements is the transition, by default, from its original SUID-based
runtime to the &lt;a class="reference external" href="https://apptainer.org/docs/admin/main/user_namespace.html"&gt;adoption of more modern Linux kernel support for user
namespaces&lt;/a&gt;.
For example, we need to be &lt;code class="docutils literal"&gt;root&lt;/code&gt; to set up a container and, when
building a container, to install packages within it. In the past, this
has been accomplished with the use of &lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;starter-suid&lt;/span&gt;&lt;/code&gt; and &lt;code class="docutils literal"&gt;fakeroot&lt;/code&gt;.
Now, by default this is accomplished using Linux user namespaces.&lt;/p&gt;
&lt;p&gt;But the questions remains: does Apptainer’s use of user namespaces
impact performance?&lt;/p&gt;
&lt;p&gt;We ran this test by physically uninstalling the &lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;apptainer-suid&lt;/span&gt;&lt;/code&gt;
package. Similar to our previous results, we found that performance was
effectively identical, once again with the most significant (but still
only slight) variations observed in the latency of &lt;code class="docutils literal"&gt;osu_alltoall&lt;/code&gt;.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="figure1.jpg" src="https://civilfritz.net/posts/benchmarking-containerized-mpi-with-apptainer-on-dell-poweredge-and-cornelis-omni-path/figure1.jpg"&gt;
&lt;/figure&gt;
&lt;/section&gt;
&lt;section id="does-behavior-change-for-multi-node-vs-single-node"&gt;
&lt;h2&gt;Does behavior change for multi-node vs. single-node?&lt;/h2&gt;
&lt;p&gt;Up to now, all of our tests have been run with one MPI task per node;
but we also wanted to check if behavior would change when multiple tasks
were run on each node. However, there have been
&lt;a class="reference external" href="https://github.com/apptainer/apptainer/issues/769"&gt;multiple&lt;/a&gt;
&lt;a class="reference external" href="https://github.com/openucx/ucx/issues/4224"&gt;reports&lt;/a&gt; of MPI breaking
in Apptainer with user namespaces, particularly when using
&lt;a class="reference external" href="https://openucx.org"&gt;UCX&lt;/a&gt;. We wanted to check if the same behavior
was observed with these libfabric builds of MPI without UCX.&lt;/p&gt;
&lt;p&gt;For this particular test case, we focused specifically on
&lt;code class="docutils literal"&gt;osu_alltoall&lt;/code&gt;, as it supports running an arbitrary number of tasks.
Rather than running one tasks per node across four nodes, we ran four
tasks on one node, with two tasks per socket.&lt;/p&gt;
&lt;p&gt;It is interesting to observe that MPICH and Open MPI latency degrades
more in this scenario than MVAPICH. We also observed (though this is not
represented in the charts) that the increase in latency is broadly
similar between host and container environments. But more to the point
of the test is the fact that MVAPICH breaks with 8MiB and larger
messages. Our current understanding is that MVAPICH optimizes intra-node
communication for different message sizes, and the method it uses for
messages 8MiB and larger is blocked by different MPI tasks running in
different user namespaces.&lt;/p&gt;
&lt;p&gt;We’ve been investigating this issue upstream for some time now,
including a &lt;a class="reference external" href="https://github.com/apptainer/apptainer-userdocs/pull/196"&gt;pull
request&lt;/a&gt;.
Check back here soon for &lt;a class="reference external" href="https://ciq.com/blog/workaround-for-communication-issue-with-mpi-apps-apptainer-without-setuid"&gt;a whole
article&lt;/a&gt;
going into detail on why it’s breaking, how you might be able to work
around it today, and how we’re hoping to fix it upstream!&lt;/p&gt;
&lt;/section&gt;
&lt;section id="conclusion"&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;While we did our best to be consistent and transparent in our
methodology, these aren’t quite what we’d consider formal results. For
example, we noticed significant performance variation from run-to-run,
particularly after rebooting nodes that had been used for previous jobs
and then sat idle. Improvements to our methodology might include reboots
between each test and averaging the results from multiple runs. (We ran
each test three times and used the third result.) All that said, we
think that even this relatively anecdotal experience confirms what we
and the Apptainer community have been saying for years: Apptainer
containerization is suitable for use with HPC applications, including
performance-sensitive MPI applications.&lt;/p&gt;
&lt;p&gt;If you’re interested in learning more about the performance you can
expect from your MPI applications in Apptainer, there are a number of
studies:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;p&gt;Evaluation and Benchmarking of Singularity MPI Containers on EU
Research e-Infrastructures, a collaborative effort by many researchers
across Europe, found that performance of containerized applications
was “very close to those obtained by the native execution.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference external" href="https://insidehpc.com/2019/06/benchmarking-mpi-applications-in-singularity-containers-on-traditional-hpc-and-cloud-infrastructures/"&gt;Benchmarking MPI Applications in Singularity Containers on
Traditional HPC and Cloud
Infrastructures&lt;/a&gt;,
by Andrei Plamada and Jarunan Panyasantisuk of ETH Zürich, “did not
experience any overhead,” but expressed concern about the need to
match the container environment with the host environment.
(&lt;a class="reference external" href="https://ciq.com/blog/a-new-approach-to-mpi-in-apptainer"&gt;Thankfully, we’ve found a solution to that particular
issue!&lt;/a&gt;)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference external" href="https://people.csail.mit.edu/dpaz/img/PDF/a065-LePaz.pdf"&gt;Performance Analysis of Applications using Singularity Container on
SDSC
Comet&lt;/a&gt;,
by Emily Le and David Paz of University of California, San Diego,
found that “its negligible performance overhead should not be a
significant decision factor when considering its intended applications
as the performance is fairly close to non-containerized jobs.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference external" href="https://www.researchgate.net/publication/326207620_Testing_MPI_Applications_Performance_in_Singularity_Containers"&gt;Testing MPI Applications Performance in Singularity
Containers&lt;/a&gt;,
by Alexey Vasyukov and Katerina A. Beklemysheva of the Moscow
Institute of Physics and Technology, found that such containers “allow
achieving performance metrics that corresponding to the values for
bare-metal in the default container setup,” with the same caveat of
concern regarding mismatched libraries between the host and container.
(Again, just to be clear, &lt;a class="reference external" href="https://ciq.com/blog/a-new-approach-to-mpi-in-apptainer"&gt;this should no longer be an
issue.&lt;/a&gt;)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;We’re hopeful that these results can let HPC administrators and users
alike proceed with confidence that they aren’t sacrificing performance
when they take advantage of the operational and flexibility benefits of
using Apptainer in their environment.&lt;/p&gt;
&lt;/section&gt;</description><category>apptainer</category><category>ciq</category><category>technology</category><guid>urn:uuid:e8c1ef31-17df-4445-a488-61dace16210f</guid><pubDate>Wed, 06 Sep 2023 06:00:00 GMT</pubDate></item><item><title>A New Approach to MPI in Apptainer | CIQ Webinar</title><link>https://civilfritz.net/posts/2023-07-14-a-new-approach-to-mpi-in-apptainer-ciq-webinar/</link><dc:creator>Jonathon Anderson</dc:creator><description>&lt;p&gt;David Godlove and I walked through the "wire-up" problem that makes MPI
awkward in containers, compared the traditional hybrid and bind
approaches, and demonstrated a new approach that runs MPI applications
completely containerized.&lt;/p&gt;
&lt;div class="youtube-video"&gt;
&lt;iframe width="560" height="315" src="https://www.youtube-nocookie.com/embed/7cw_uVr5Ibk?rel=0&amp;amp;wmode=transparent" frameborder="0" allow="encrypted-media" allowfullscreen&gt;&lt;/iframe&gt;
&lt;/div&gt;</description><category>apptainer</category><category>ciq</category><category>technology</category><guid>urn:uuid:674b6873-010c-4710-9c2e-bb845b61ccda</guid><pubDate>Fri, 14 Jul 2023 06:00:00 GMT</pubDate></item><item><title>Managing Containerized Services with Apptainer and Systemd</title><link>https://civilfritz.net/posts/managing-containerized-services-with-apptainer-and-systemd/</link><dc:creator>Jonathon Anderson</dc:creator><description>&lt;p&gt;&lt;a class="reference external" href="https://ciq.com/blog/managing-containerized-services-with-apptainer-and-systemd"&gt;This article was also published via the CIQ blog on 17 April 2023.&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Apptainer is often compared to Docker as both a container runtime engine
and container management environment. In general, each tool targets a
different use case; but the two projects notably differ in their runtime
strategy. In general, Docker is designed to host system services, and
Apptainer is designed to containerize end-user applications (often in a
batch-processing environment). Because of its service-oriented
architecture, Docker containers are most commonly started in the
background and run indefinitely. Apptainer has support for service
containers, but Apptainer containers are most commonly started in the
foreground for temporal, interactive use.&lt;/p&gt;
&lt;p&gt;Apptainer’s architecture, however, is ultimately a more natural fit for
the Linux ecosystem, as it comes with fewer embedded assumptions and is,
ultimately, more flexible.&lt;/p&gt;
&lt;p&gt;In the time since Docker’s architecture was first established, systemd
has arisen as the de facto standard for service management in Linux. As
such, we can easily use systemd to manage system services containerized
with Apptainer. This technique should be compatible with most major
Linux operating systems, including Rocky Linux,
&lt;a class="reference external" href="https://ciq.com/glossary/centos"&gt;CentOS&lt;/a&gt; Stream, and Suse.&lt;/p&gt;
&lt;section id="a-minimal-service-container"&gt;
&lt;h2&gt;A minimal service container&lt;/h2&gt;
&lt;p&gt;First, here’s a an example definition file to use as a system service:&lt;/p&gt;
&lt;pre class="literal-block"&gt;Bootstrap: docker
From: alpine:latest

%runscript
env; while true; do date; sleep 10; done&lt;/pre&gt;
&lt;p&gt;This is just a minimal Alpine Linux container that prints the current
environment and then loops, printing the current date and time every 10
seconds. This suffices as an example system service that will run
“forever” and that produces regular output, allowing us to confirm that
the service is running properly.&lt;/p&gt;
&lt;p&gt;I placed the example container at
/usr/local/lib/apptainer/env-service.sif. (We’ll refer to that path
later.)&lt;/p&gt;
&lt;pre class="literal-block"&gt;$ apptainer build alpine-sleeper.sif alpine-sleeper.def
INFO:    Starting build...
Getting image source signatures
Copying blob f56be85fc22e skipped: already exists
Copying config 4798f93a2c done
Writing manifest to image destination
Storing signatures
2023/04/03 16:25:13  info unpack layer: sha256:
f56be85fc22e46face30e2c3de3f7fe7c15f8fd7c4e5add29d7f64b87abdaa09
INFO: Adding runscript
INFO: Creating SIF file...
INFO: Build complete: alpine-sleeper.sif

$ sudo mkdir -p /usr/local/lib/apptainer/
$ sudo mv alpine-sleeper.sif /usr/local/lib/apptainer/&lt;/pre&gt;
&lt;/section&gt;
&lt;section id="systemd-unit-file"&gt;
&lt;h2&gt;systemd unit file&lt;/h2&gt;
&lt;p&gt;I then installed the following systemd unit file at
/etc/systemd/system/apptainer@.service:&lt;/p&gt;
&lt;pre class="literal-block"&gt;[Unit]
Description=Apptainer container: %I
After=network-online.target
Wants=network-online.target

[Service]
ExecStart=/usr/bin/apptainer run /usr/local/lib/apptainer/%i.sif
EnvironmentFile=-/etc/sysconfig/apptainer/%i.env
EnvironmentFile=-/etc/default/apptainer/%i.env

[Install]
WantedBy=multi-user.target&lt;/pre&gt;
&lt;p&gt;This unit file is a template that can start an Apptainer container from
an image stored at /usr/local/lib/apptainer/.&lt;/p&gt;
&lt;p&gt;The unit file will also optionally read environment configuration files
from either /etc/sysconfig/apptainer/ or /etc/default/apptainer/.&lt;/p&gt;
&lt;p&gt;The first time you put the unit file in place you’ll need to tell
systemd to reload its configuration to make it available. (This is
otherwise automatic on boot.)&lt;/p&gt;
&lt;pre class="literal-block"&gt;systemctl daemon-reload&lt;/pre&gt;
&lt;/section&gt;
&lt;section id="configuring-and-starting-the-service"&gt;
&lt;h2&gt;Configuring and starting the service&lt;/h2&gt;
&lt;p&gt;To demonstrate the configurability of the service environment, I placed
an environment file at /etc/sysconfig/apptainer/alpine- sleeper.env.&lt;/p&gt;
&lt;pre class="literal-block"&gt;TEST_VARIABLE=nar_value&lt;/pre&gt;
&lt;p&gt;You can now enable the service to run automatically at boot and/or start
it immediately, as with any systemd service:&lt;/p&gt;
&lt;pre class="literal-block"&gt;$ sudo systemctl start apptainer@alpine-sleeper
$ sudo systemctl status apptainer@alpine-sleeper
 apptainer@alpine-sleeper.service - Apptainer container: alpine/sleeper
   Loaded: loaded (/etc/systemd/system/apptainer@.service; disabled; vendor preset: disabled)
   Active: active (running) since Tue 2023-04-04 11:46:31 MDT; 1s ago
 Main PID: 107209 (starter)
    Tasks: 9 (limit: 11364)
   Memory: 11.3M
   CGroup: /system.slice/system-apptainer.slice/apptainer@alpine-
sleeper.service
           107209 Apptainer runtime parent
           107224 /bin/sh /.singularity.d/runscript
           107249 sleep 10

Apr 04 11:46:31 rocky3 apptainer[107247]: LANG=en_US.UTF-8
Apr 04 11:46:31 rocky3 apptainer[107247]: PROMPT_COMMAND=PS1="
Apptainer&amp;gt; "; unset PROMPT_COMMAND
Apr 04 11:46:31 rocky3 apptainer[107247]: APPTAINER_BIND=
Apr 04 11:46:31 rocky3 apptainer[107247]: APPTAINER_CONTAINER=/usr/local
/lib/apptainer/alpine-sleeper.sif
Apr 04 11:46:31 rocky3 apptainer[107247]: SINGULARITY_BIND=
Apr 04 11:46:31 rocky3 apptainer[107247]: SINGULARITY_CONTAINER=/usr
/local/lib/apptainer/alpine-sleeper.sif
Apr 04 11:46:31 rocky3 apptainer[107247]: APPTAINER_NAME=alpine-sleeper.
sif
Apr 04 11:46:31 rocky3 apptainer[107247]: PWD=/
Apr 04 11:46:31 rocky3 apptainer[107247]: SINGULARITY_NAME=alpine-
sleeper.sif
Apr 04 11:46:31 rocky3 apptainer[107248]: Tue Apr  4 11:46:31 MDT 2023&lt;/pre&gt;
&lt;p&gt;The string to the right of the @ populates the %i and %I variables
inside the unit file template, allowing you to manage any such container
with the single unit file, each with a discrete set of input variables.&lt;/p&gt;
&lt;p&gt;Further, the specified environment variables are passed through to the
process inside the container.&lt;/p&gt;
&lt;pre class="literal-block"&gt;$ journalctl -u apptainer@alpine-sleeper | grep TEST_VARIABLE
Apr 04 11:48:18 rocky3 apptainer[107375]: TEST_VARIABLE=nar_value&lt;/pre&gt;
&lt;/section&gt;
&lt;section id="monitoring-the-service"&gt;
&lt;h2&gt;Monitoring the service&lt;/h2&gt;
&lt;p&gt;Recent logs for the service are available in the systemctl status
output, and you can retrieve full logs using journalctl. e.g.,&lt;/p&gt;
&lt;pre class="literal-block"&gt;journalctl -u apptainer@env-service.service&lt;/pre&gt;
&lt;p&gt;Because systemd typically runs each service in its own cgroup
automatically, we even get cgroup-based process isolation for free with
this technique. See the above systemctl status output, which reports the
number of tasks, the total CPU time, and even the amount of memory
consumed by the service and, by extension, the container.&lt;/p&gt;
&lt;p&gt;Finally, process management works as you expect. I can stop the service,
and the container stops as well.&lt;/p&gt;
&lt;pre class="literal-block"&gt;$ pgrep -lif apptainer
107574 starter

$ sudo systemctl stop apptainer@alpine-sleeper
$ pgrep -lif apptainer || echo not running
not running&lt;/pre&gt;
&lt;p&gt;And if the process dies, the service reflects this.&lt;/p&gt;
&lt;pre class="literal-block"&gt;$ sudo systemctl start apptainer@alpine-sleeper
$ sudo systemctl status apptainer@alpine-sleeper
 apptainer@alpine-sleeper.service - Apptainer container: alpine/sleeper
   Loaded: loaded (/etc/systemd/system/apptainer@.service; disabled; vendor preset: disabled)
   Active: active (running) since Tue 2023-04-04 11:53:27 MDT; 10s ago
 Main PID: 107637 (starter)
    Tasks: 10 (limit: 11364)
   Memory: 11.8M
   CGroup: /system.slice/system-apptainer.slice/apptainer@alpine-
sleeper.service
           107637 Apptainer runtime parent
           107651 /bin/sh /.singularity.d/runscript
           107682 sleep 10

Apr 04 11:53:27 rocky3 apptainer[107674]: PROMPT_COMMAND=PS1="
Apptainer&amp;gt; "; unset PROMPT_COMMAND
Apr 04 11:53:27 rocky3 apptainer[107674]: APPTAINER_BIND=
Apr 04 11:53:27 rocky3 apptainer[107674]: APPTAINER_CONTAINER=/usr/local
/lib/apptainer/alpine-sleeper.sif
Apr 04 11:53:27 rocky3 apptainer[107674]: SINGULARITY_BIND=
Apr 04 11:53:27 rocky3 apptainer[107674]: SINGULARITY_CONTAINER=/usr
/local/lib/apptainer/alpine-sleeper.sif
Apr 04 11:53:27 rocky3 apptainer[107674]: APPTAINER_NAME=alpine-sleeper.
sif
Apr 04 11:53:27 rocky3 apptainer[107674]: PWD=/
Apr 04 11:53:27 rocky3 apptainer[107674]: SINGULARITY_NAME=alpine-
sleeper.sif
Apr 04 11:53:27 rocky3 apptainer[107675]: Tue Apr  4 11:53:27 MDT 2023
Apr 04 11:53:37 rocky3 apptainer[107681]: Tue Apr  4 11:53:37 MDT 2023

$ sudo kill 107651
$ sudo systemctl status apptainer@alpine-sleeper
 apptainer@alpine-sleeper.service - Apptainer container: alpine/sleeper
   Loaded: loaded (/etc/systemd/system/apptainer@.service; disabled;
vendor preset: disabled)
   Active: inactive (dead)

Apr 04 11:53:27 rocky3 apptainer[107674]: APPTAINER_CONTAINER=/usr/local
/lib/apptainer/alpine-sleeper.sif
Apr 04 11:53:27 rocky3 apptainer[107674]: SINGULARITY_BIND=
Apr 04 11:53:27 rocky3 apptainer[107674]: SINGULARITY_CONTAINER=/usr
/local/lib/apptainer/alpine-sleeper.sif
Apr 04 11:53:27 rocky3 apptainer[107674]: APPTAINER_NAME=alpine-sleeper.
sif
Apr 04 11:53:27 rocky3 apptainer[107674]: PWD=/
Apr 04 11:53:27 rocky3 apptainer[107674]: SINGULARITY_NAME=alpine-
sleeper.sif
Apr 04 11:53:27 rocky3 apptainer[107675]: Tue Apr  4 11:53:27 MDT 2023
Apr 04 11:53:37 rocky3 apptainer[107681]: Tue Apr  4 11:53:37 MDT 2023
Apr 04 11:53:47 rocky3 apptainer[107687]: Tue Apr  4 11:53:47 MDT 2023
Apr 04 11:53:48 rocky3 systemd[1]: apptainer@alpine-sleeper.service:
Succeeded.&lt;/pre&gt;
&lt;p&gt;You could even configure systemd to automatically restart the service,
e.g., by specifying Restart=always.&lt;/p&gt;
&lt;/section&gt;
&lt;section id="conclusion"&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Using systemd for Apptainer process management is different than Docker,
but ultimately integrates with other traditional system services more
seamlessly. Notably, Podman—a OCI-based Docker alternative included with
Rocky Linux and many other Linux distributions—has first-class support
for generating such systemd unit files as well.&lt;/p&gt;
&lt;p&gt;You can read more about the configurability of systemd service unit
files at
&lt;a class="reference external" href="https://www.freedesktop.org/software/systemd/man/systemd.service.html"&gt;https://www.freedesktop.org/software/systemd/man/systemd.service.html&lt;/a&gt;.
Since this technique turns Apptainer containers into standard systemd
services, you have access to all the service and process management
capabilities of systemd, including declarative dependency management,
process monitoring, and output capture.&lt;/p&gt;
&lt;/section&gt;</description><category>apptainer</category><category>ciq</category><category>technology</category><guid>urn:uuid:831b4be1-7d1c-4a36-b57a-e04e79b19763</guid><pubDate>Mon, 17 Apr 2023 06:00:00 GMT</pubDate></item></channel></rss>