<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.anunna.wur.nl/index.php?action=history&amp;feed=atom&amp;title=Tutorials%2FApptainer-Conda</id>
	<title>Tutorials/Apptainer-Conda - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.anunna.wur.nl/index.php?action=history&amp;feed=atom&amp;title=Tutorials%2FApptainer-Conda"/>
	<link rel="alternate" type="text/html" href="https://wiki.anunna.wur.nl/index.php?title=Tutorials/Apptainer-Conda&amp;action=history"/>
	<updated>2026-08-29T10:48:44Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.3</generator>
	<entry>
		<id>https://wiki.anunna.wur.nl/index.php?title=Tutorials/Apptainer-Conda&amp;diff=3063&amp;oldid=prev</id>
		<title>Honfi001 at 15:10, 17 August 2026</title>
		<link rel="alternate" type="text/html" href="https://wiki.anunna.wur.nl/index.php?title=Tutorials/Apptainer-Conda&amp;diff=3063&amp;oldid=prev"/>
		<updated>2026-08-17T15:10:11Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 15:10, 17 August 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{DISPLAYTITLE:&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Totorial&lt;/del&gt;: Conda in an Apptainer Container}}&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{DISPLAYTITLE:&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Tutorial&lt;/ins&gt;: Conda in an Apptainer Container}}&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;= Running a Conda Environment in a Container =&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;= Running a Conda Environment in a Container =&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Honfi001</name></author>
	</entry>
	<entry>
		<id>https://wiki.anunna.wur.nl/index.php?title=Tutorials/Apptainer-Conda&amp;diff=3062&amp;oldid=prev</id>
		<title>Honfi001: Created page with &quot;{{DISPLAYTITLE:Totorial: Conda in an Apptainer Container}} = Running a Conda Environment in a Container =  Sometimes a piece of software is published only as a conda package, with no module, no Python-only equivalent and no ready-made image. Building it into a container is the cleanest way to run it on Anunna: the environment is created once, on a compute node, and afterwards it is a single file that behaves the same way every time you use it.  Read Python/Conda firs...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.anunna.wur.nl/index.php?title=Tutorials/Apptainer-Conda&amp;diff=3062&amp;oldid=prev"/>
		<updated>2026-08-17T15:09:47Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;{{DISPLAYTITLE:Totorial: Conda in an Apptainer Container}} = Running a Conda Environment in a Container =  Sometimes a piece of software is published only as a conda package, with no module, no Python-only equivalent and no ready-made image. Building it into a container is the cleanest way to run it on Anunna: the environment is created once, on a compute node, and afterwards it is a single file that behaves the same way every time you use it.  Read &lt;a href=&quot;/Python/Conda&quot; title=&quot;Python/Conda&quot;&gt;Python/Conda&lt;/a&gt; firs...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{DISPLAYTITLE:Totorial: Conda in an Apptainer Container}}&lt;br /&gt;
= Running a Conda Environment in a Container =&lt;br /&gt;
&lt;br /&gt;
Sometimes a piece of software is published only as a conda package, with no module, no Python-only equivalent and no ready-made image. Building it into a container is the cleanest way to run it on Anunna: the environment is created once, on a compute node, and afterwards it is a single file that behaves the same way every time you use it.&lt;br /&gt;
&lt;br /&gt;
Read [[Python/Conda]] first if you have not already. This tutorial is the last resort described at the end of that page, not the recommended route.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Important:&amp;#039;&amp;#039;&amp;#039; Before you begin, make sure the following are in place:&lt;br /&gt;
&lt;br /&gt;
* You are running on a &amp;#039;&amp;#039;&amp;#039;compute node&amp;#039;&amp;#039;&amp;#039;, not a login node. Request an interactive session first — see [[Interactive Jobs]].&lt;br /&gt;
* Your &amp;lt;code&amp;gt;.sif&amp;lt;/code&amp;gt; image files should be stored on &amp;#039;&amp;#039;&amp;#039;Lustre&amp;#039;&amp;#039;&amp;#039;, not in your home directory. SIF files can be large and will eat through your home quota fast.&lt;br /&gt;
* Set your Apptainer cache to Lustre as well. Add this to your session (or your &amp;lt;code&amp;gt;.bashrc&amp;lt;/code&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export APPTAINER_CACHEDIR=$myScratch/apptainer_cache&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Getting Started ==&lt;br /&gt;
&lt;br /&gt;
Load the required modules:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
module reset&lt;br /&gt;
module load utilities Apptainer&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Three things to know first ==&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;A container should not be your first move.&amp;#039;&amp;#039;&amp;#039; Always prefer software we already provide as [[Environment Modules|modules]], or a [[Python/Modules#Virtual environments|virtual environment]] built on one of our Python modules. Those are compiled for this machine and we are far better placed to help you when something goes wrong. [[Support|Ask us]] if what you need is missing.&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;This tutorial uses micromamba, not conda.&amp;#039;&amp;#039;&amp;#039; Micromamba is a single small program that installs conda packages, and it takes them from conda-forge and bioconda rather than from Anaconda&amp;#039;s own repository. That keeps you clear of the licensing conditions described in [[Python/Conda#How they differ]].&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;The image we build is read-only.&amp;#039;&amp;#039;&amp;#039; Everything the environment needs is decided up front and baked in. Do not try to install software interactively inside a running container: the changes will not survive, and you lose the one real advantage of doing this, which is that the result is reproducible.&lt;br /&gt;
&lt;br /&gt;
== Step 1: Describe the environment ==&lt;br /&gt;
&lt;br /&gt;
Create a file called &amp;lt;code&amp;gt;environment.yml&amp;lt;/code&amp;gt;. This is where you name the environment, list the packages you want, and say which repositories to take them from.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;yaml&amp;quot;&amp;gt;&lt;br /&gt;
name: base&lt;br /&gt;
channels:&lt;br /&gt;
  - conda-forge&lt;br /&gt;
  - bioconda&lt;br /&gt;
dependencies:&lt;br /&gt;
  - python&lt;br /&gt;
  - pip&lt;br /&gt;
  - star&lt;br /&gt;
  - bwa&lt;br /&gt;
  - multiqc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Two notes on this file. Keep the name as &amp;lt;code&amp;gt;base&amp;lt;/code&amp;gt;, because that is the environment micromamba&amp;#039;s image already has and installing into it saves a step. And for real work, pin your versions — &amp;lt;code&amp;gt;multiqc=1.29&amp;lt;/code&amp;gt; rather than &amp;lt;code&amp;gt;multiqc&amp;lt;/code&amp;gt; — otherwise rebuilding the image in six months will quietly give you different software.&lt;br /&gt;
&lt;br /&gt;
== Step 2: Write the definition file ==&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;&amp;#039;definition file&amp;#039;&amp;#039;&amp;#039; describes how the container is built, step by step. Create &amp;lt;code&amp;gt;image.def&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Bootstrap: docker&lt;br /&gt;
From: mambaorg/micromamba:latest&lt;br /&gt;
&lt;br /&gt;
%files&lt;br /&gt;
    environment.yml /environment.yml&lt;br /&gt;
&lt;br /&gt;
%post&lt;br /&gt;
    micromamba install -n base --file /environment.yml &amp;amp;&amp;amp; \&lt;br /&gt;
        micromamba clean --all --yes&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Each part in turn:&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;Bootstrap&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;From&amp;lt;/code&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
Start from a Docker image that already has micromamba installed, so we do not have to install it ourselves.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;%files&amp;lt;/code&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
Copy &amp;lt;code&amp;gt;environment.yml&amp;lt;/code&amp;gt; from your directory on Anunna into the container, so the next step can read it.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;%post&amp;lt;/code&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
Run micromamba inside the container to install everything listed in the file, then delete its download cache. That last part matters: without &amp;lt;code&amp;gt;clean&amp;lt;/code&amp;gt;, the cache is baked into the image and can easily double its size.&lt;br /&gt;
&lt;br /&gt;
== Step 3: Build the image ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
apptainer build image.sif image.def&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This takes a few minutes and produces a single file, &amp;lt;code&amp;gt;image.sif&amp;lt;/code&amp;gt;, containing the whole environment.&lt;br /&gt;
&lt;br /&gt;
If the build fails complaining about directories from the host, clear Apptainer&amp;#039;s bind list for the duration of the build:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
APPTAINER_BIND=&amp;#039; &amp;#039; apptainer build image.sif image.def&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Testing the image ==&lt;br /&gt;
&lt;br /&gt;
Check that the software is really there:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
apptainer run image.sif multiqc --help&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should see MultiQC&amp;#039;s own help text, beginning with its version number and a usage line. If instead you get an error saying the command was not found, read the note below.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Use &amp;lt;code&amp;gt;run&amp;lt;/code&amp;gt;, not &amp;lt;code&amp;gt;exec&amp;lt;/code&amp;gt;.&amp;#039;&amp;#039;&amp;#039; The micromamba image activates the environment as it starts up, and &amp;lt;code&amp;gt;apptainer run&amp;lt;/code&amp;gt; goes through that startup step while &amp;lt;code&amp;gt;apptainer exec&amp;lt;/code&amp;gt; skips it. With &amp;lt;code&amp;gt;exec&amp;lt;/code&amp;gt; you will most likely be told the command cannot be found, even though it is installed.&lt;br /&gt;
&lt;br /&gt;
== Using it in a job ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
#SBATCH --job-name=multiqc&lt;br /&gt;
#SBATCH --time=1:00:00&lt;br /&gt;
#SBATCH --cpus-per-task=4&lt;br /&gt;
#SBATCH --mem=16G&lt;br /&gt;
&lt;br /&gt;
module load utilities Apptainer&lt;br /&gt;
&lt;br /&gt;
apptainer run --bind /lustre $myNobackup/images/image.sif multiqc /path/to/results&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Apptainer does not automatically make every filesystem visible inside the container, so &amp;lt;code&amp;gt;--bind /lustre&amp;lt;/code&amp;gt; ensures your data can be read.&lt;br /&gt;
&lt;br /&gt;
== Where to keep your images ==&lt;br /&gt;
&lt;br /&gt;
Image files are large. Keep them on Lustre, under &amp;lt;code&amp;gt;$myNobackup&amp;lt;/code&amp;gt;, and not in your home directory.&lt;br /&gt;
&lt;br /&gt;
If several people in your group use the same software, put one copy somewhere shared instead of each keeping their own — see [[Shared Storage]]. A container is a single file and is identical for everyone who runs it, which is precisely what makes sharing it worthwhile.&lt;br /&gt;
&lt;br /&gt;
One habit worth forming: identify an image by what is inside it, using &amp;lt;code&amp;gt;apptainer inspect&amp;lt;/code&amp;gt;, rather than by trusting its file name.&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Step !! Command&lt;br /&gt;
|-&lt;br /&gt;
| Load Apptainer || &amp;lt;code&amp;gt;module reset &amp;amp;&amp;amp; module load utilities Apptainer&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Describe the environment || Write &amp;lt;code&amp;gt;environment.yml&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Describe the container || Write &amp;lt;code&amp;gt;image.def&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Build the image || &amp;lt;code&amp;gt;apptainer build image.sif image.def&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Run something in it || &amp;lt;code&amp;gt;apptainer run image.sif &amp;amp;lt;command&amp;amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Inspect it || &amp;lt;code&amp;gt;apptainer inspect image.sif&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[Python/Conda]]&lt;br /&gt;
* [[Apptainer]]&lt;br /&gt;
* [[Tutorials/Apptainer-Introduction]]&lt;br /&gt;
* [[Tutorials/Apptainer-DefinitionFiles]]&lt;br /&gt;
* [[Interactive Jobs]]&lt;br /&gt;
* [[Batch Jobs]]&lt;br /&gt;
* [[Shared Storage]]&lt;br /&gt;
&lt;br /&gt;
== External links ==&lt;br /&gt;
&lt;br /&gt;
* [https://mamba.readthedocs.io/en/latest/user_guide/micromamba.html micromamba documentation]&lt;br /&gt;
* [https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#create-env-file-manually Writing an environment.yml file]&lt;br /&gt;
* [https://apptainer.org/docs/user/main/definition_files.html Apptainer definition files]&lt;br /&gt;
* [https://depot.galaxyproject.org/singularity/ Prebuilt bioconda container images]&lt;/div&gt;</summary>
		<author><name>Honfi001</name></author>
	</entry>
</feed>