Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
habrok:examples:apptainer [2026/06/29 12:45] – [Using a GPU in your container] pedrohabrok:examples:apptainer [2026/09/15 11:16] (current) admin
Line 7: Line 7:
 A container is an isolated runtime environment that is often used to run a packaged version of some software (and its dependencies). A container is based on an image that defines the software environment, and can be run on any machine that supports your container technology. This allows you to run your application inside this container environment, which is always the same, regardless of the (operating) system you are running on. The container image usually contains a minimal version of a base operating system and you can extend it with as many libraries and applications as you want or need. A container is an isolated runtime environment that is often used to run a packaged version of some software (and its dependencies). A container is based on an image that defines the software environment, and can be run on any machine that supports your container technology. This allows you to run your application inside this container environment, which is always the same, regardless of the (operating) system you are running on. The container image usually contains a minimal version of a base operating system and you can extend it with as many libraries and applications as you want or need.
  
-A container for instance allows you to run Ubuntu applications in an Ubuntu environment on a CentOS machine. The nice thing is that you can control (almost) the complete environment you are running on without needing root permissions on the host machine. +A container for instance allows you to run Ubuntu applications in an Ubuntu environment on a RedHat machine. The nice thing is that you can control (almost) the complete environment you are running on without needing root permissions on the host machine. 
  
 A popular container technology is Docker, but this is not suitable for shared systems like HPC clusters. As an alternative, you can make use of [[https://apptainer.org/|Apptainer containers]] previously known as Singularity) on Hábrók. A popular container technology is Docker, but this is not suitable for shared systems like HPC clusters. As an alternative, you can make use of [[https://apptainer.org/|Apptainer containers]] previously known as Singularity) on Hábrók.
Line 25: Line 25:
 Note that FSL is available as a module as well, but this does not include all the FSL tools, as the current installation method to install the full FSL suite is not supported on Hábrók. Note that FSL is available as a module as well, but this does not include all the FSL tools, as the current installation method to install the full FSL suite is not supported on Hábrók.
  
-There are several containers for FSL available on Docker Hub; for this example we will be using the following one: +There are several containers for FSL available on Docker Hub; for this example we will be using the following one: 
-https://hub.docker.com/r/diannepat/fsl6+https://hub.docker.com/r/brainlife/fsl
  
 ==== Set the Apptainer cache directory ==== ==== Set the Apptainer cache directory ====
Line 40: Line 40:
 In order to use this container on Hábrók, we are first going to pull it in and store it on Hábrók. This process should be done on the interactive node on Hábrók, as it may take up some CPU resources. Since the image is very large (several gigabytes!), you should run the command in a directory on the ''/scratch'' file system: In order to use this container on Hábrók, we are first going to pull it in and store it on Hábrók. This process should be done on the interactive node on Hábrók, as it may take up some CPU resources. Since the image is very large (several gigabytes!), you should run the command in a directory on the ''/scratch'' file system:
 <code bash> <code bash>
-apptainer pull docker://diannepat/fsl6+apptainer pull docker://brainlife/fsl:6.0.7.22
 </code> </code>
-This will fetch the container image from Docker Hub and convert it to an Apptainer format, which may take a bit of time. When it's done, you will find a file named ''fsl6_latest.sif'' in your working directory.+This will fetch the container image for FSL 6.0.7.22 from Docker Hub and convert it to an Apptainer format, which may take a bit of time. When it's done, you will find a file named ''fsl_6.0.7.22.sif'' in your working directory.
  
 ==== Start an interactive shell within your container ==== ==== Start an interactive shell within your container ====
Line 48: Line 48:
 Now that you have the image, you may want to look around in the container and try running some commands interactively. You can do this by launching a shell within the container: Now that you have the image, you may want to look around in the container and try running some commands interactively. You can do this by launching a shell within the container:
 <code bash> <code bash>
-apptainer shell fsl6_latest.sif+apptainer shell fsl_6.0.7.22.sif
 </code> </code>
  
Line 58: Line 58:
  
 <code bash> <code bash>
-apptainer exec fsl6_latest.sif fsl_anat <arguments>+apptainer exec fsl_6.0.7.22.sif fsl_anat <arguments>
 </code> </code>
  
Line 64: Line 64:
  
 <code bash> <code bash>
-apptainer exec /scratch/$USER/fsl6_latest.sif fsl_anat <arguments>+apptainer exec /scratch/$USER/fsl_6.0.7.22.sif fsl_anat <arguments>
 </code> </code>
  
Line 73: Line 73:
 For instance, if you want to make your scratch folder available, so that FSL can actually access it, you can do: For instance, if you want to make your scratch folder available, so that FSL can actually access it, you can do:
 <code bash> <code bash>
-apptainer exec -B /scratch/$USER /scratch/$USER/fsl6_latest.sif fsl_anat <arguments>+apptainer exec -B /scratch/$USER /scratch/$USER/fsl_6.0.7.22.sif fsl_anat <arguments>
 </code> </code>
  
Line 80: Line 80:
 In order to make a GPU available in the container, you will have to use the ''%%--%%nv'' flag for the Apptainer subcommand, e.g.: In order to make a GPU available in the container, you will have to use the ''%%--%%nv'' flag for the Apptainer subcommand, e.g.:
 <code bash> <code bash>
-apptainer exec --nv /scratch/$USER/fsl6_latest.sif fsl_anat <arguments>+apptainer exec --nv /scratch/$USER/fsl_6.0.7.22.sif fsl_anat <arguments>
 </code> </code>
  
 Note that this only makes sense if you are running the container in a GPU enabled node. Those would be the interactive GPU nodes ''gpu1.hb.hpc.rug.nl'' and ''gpu2.hb.hpc.rug.nl'' or as part of [[..:advanced_job_management:running_jobs_on_gpus|GPU jobs]]. Note that this only makes sense if you are running the container in a GPU enabled node. Those would be the interactive GPU nodes ''gpu1.hb.hpc.rug.nl'' and ''gpu2.hb.hpc.rug.nl'' or as part of [[..:advanced_job_management:running_jobs_on_gpus|GPU jobs]].