cc_staff
156
edits
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
{{Draft}} | {{Draft}} | ||
= | =Notices= | ||
This page is '''draft work-in-progress'''. At the time of writing (August 2022) Apptainer version 1.1 is in release candidate status and the full release may well induce further updates to this page. (This page's current content is correct for Apptainer version 1.0.) | This page is '''draft work-in-progress'''. At the time of writing (August 2022) Apptainer version 1.1 is in release candidate status and the full release may well induce further updates to this page. (This page's current content is correct for Apptainer version 1.0.) | ||
==Official Apptainer Documentation== | |||
This page is neither exhaustive nor all-features complete and does not replace [http://apptainer.org/docs|Apptainer's official documentation], rather, it summarizes basic use, documents some aspects of using Apptainer on Alliance systems, and provides some examples relevant in using Apptainer on Alliance systems. We recommend all users read the official Apptainer documentation concerning the features of Apptainer they are using. | |||
==If Currently Using Singularity== | ==If Currently Using Singularity== | ||
Line 36: | Line 40: | ||
===Important Items=== | ===Important Items=== | ||
====<code>sudo</code> | ====<code>sudo</code>==== | ||
Many users ask about | Many users ask about <code>sudo</code> since documentation and web sites often discuss using <code>sudo</code>. Know the ability to use <code>sudo</code> to obtain root permissions is not available on our clusters. Should you require using <code>sudo</code>, consider the following options: | ||
* Install Linux, Apptainer, and <code>sudo</code> in a virtual machine on a system you control | * Install Linux, Apptainer, and <code>sudo</code> in a virtual machine on a system you control so you will be able to have <code>sudo</code> access within such. Build your image(s) on that machine and upload them in order to use them on Alliance systems. | ||
* If appropriate, [[Technical Support|submit a ticket]] asking if Alliance staff would be able to help build the image(s), etc. required needing <code>sudo</code>. (Understand that this may or may not be possible --but ask in a ticket if what you wish to achieve is beyond your means | * If appropriate, [[Technical Support|submit a ticket]] asking if Alliance staff would be able to help build the image(s), etc. required needing <code>sudo</code>. (Understand that this may or may not be done/possible --but feel free to ask such in a ticket if what you wish to achieve is beyond your means. Additionally, we may respond with other ways to achieve such with may or may not involve Apptainer.) | ||
NOTE: Apptainer version 1.1, which as of August 2022 has release candidate status only, may well allow users to easily use the <code>--fakeroot</code> option with various Apptainer commands. Such should make it possible to do various things without <code>sudo</code>. If so, after Apptainer version 1.1 has been released, this web page will be updated concerning such. | |||
====Important Command Line Options==== | ====Important Command Line Options==== | ||
Line 62: | Line 67: | ||
|} | |} | ||
There is another important option, <code>-W</code> or <code>--workdir</code>, one should consider using. On Alliance clusters and on most Linux systems, <code>/tmp</code> and similar filesystems use RAM --not disk space. Since jobs typically run on our clusters with limited RAM amounts, this can easily result in jobs getting killed because they consume too much RAM relative to what was requested for the job. A suitable work-around for this is to tell Apptainer to use actual disk space location for its "workdir". This is done by passing the <code>-W</code> option followed by a path to a disk space location where Apptainer can read/write temporary files, etc. For example, suppose one wanted to run a command <code>myprogram</code> in a using an Apptainer container image called <code>myimage.sif</code> with its "workdir" set to <code>$HOME/aworkdir</code> in the filesystem: | |||
<source lang="console">$ mkdir -p $HOME/aworkdir | |||
$ apptainer run -C -B /home -W $HOME/aworkdir myimage.sif myprogram</source> | |||
where: | |||
* The workdir directory can be removed if there are no live containers using it. | |||
* When using Apptainer in an <code>salloc</code> or an <code>sbatch</code> job, use <code>${SLURM_TMPDIR}</code> for the "workdir" location, e.g., <code>-W ${SLURM_TMPDIR}</code>. | |||
** ASIDE: One should '''not''' be running programs (including using Apptainer) on a login node: use an interactive <code>salloc</code> job. | |||
* When using bind mounts, see the [[Bind_Mounts|section on bind mounts]] below since not all Alliance clusters are the same concerning the exact bind mounts that are needed to access <code>/home</code>, <code>/project</code>, and <code>/scratch</code>. | |||
====Using GPUs==== | ====Using GPUs==== | ||
Line 77: | Line 91: | ||
====Using MPI Programs==== | ====Using MPI Programs==== | ||
If you want to run MPI programs inside a container there are things that need to be done in the host environment in order for such to work. Please see the [[#Running_MPI_Programs_Inside_an_Apptainer Container|Running MPI Programs section below]] for an example of how to run MPI programs inside a container. | If you want to run MPI programs inside a container there are things that need to be done in the host environment in order for such to work. Please see the [[#Running_MPI_Programs_Inside_an_Apptainer Container|Running MPI Programs section below]] for an example of how to run MPI programs inside a container. The official Apptainer documentation has more information concerning how MPI programs can be run inside a container. | ||
===Container-Specific Help: <code>apptainer run-help</code>=== | ===Container-Specific Help: <code>apptainer run-help</code>=== | ||
Line 113: | Line 127: | ||
==Building an Apptainer Container/Image== | ==Building an Apptainer Container/Image== | ||
Apptainer images can be created in the following formats: | Apptainer "images" can be created in the following formats: | ||
* as an <code>SIF</code> file, or, | * as an <code>SIF</code> file, or, | ||
* as a "sandbox" directory. | * as a "sandbox" directory. | ||
<code>SIF</code> files can contain multiple | <code>SIF</code> files internally can contain multiple parts where each part is typically a squashfs filesystem (which are read-only and compressed). It is possible for <code>SIF</code> files to contain read-write filesystems and overlay images as well --but such is beyond the scope of this page: see the official Apptainer documentation on how to do such. Unless more advanced methods of building an "image" were used, the Apptainer <code>build</code> command produces a <code>SIF</code> file with a read-only squashfs filesystem when building images. (This is the preferred option since the resulting image remains as-is since it is read-only, and, the image is much smaller since it is compressed. Know that disk reads from that image are done very quickly.) | ||
A "sandbox" directory is a normal directory in the filesystem that starts out as empty and as Apptainer builds the image it adds the files, etc. needed in the image to that directory. The contents of a "sandbox" directory should only be accessed, updated, etc. through the use of Apptainer. One might need to use a "sandbox" directory in situations where one needs read-write access in order to be able to update the container image. | A "sandbox" directory is a normal directory in the filesystem that starts out as empty and as Apptainer builds the image it adds the files, etc. needed in the image to that directory. The contents of a "sandbox" directory should only be accessed, updated, etc. through the use of Apptainer. One might need to use a "sandbox" directory in situations where one needs to have read-write access to the image itself in order to be able to update the container image. That said, if updates are infrequent, it is typically easier and better to use an <code>SIF</code> and when updates need to be done, build a sandbox image from the <code>SIF</code> file, make the required changes, and then build a new <code>SIF</code> file, e.g., | ||
<source lang="console">$ cd $HOME | |||
$ mkdir mynewimage.dir | |||
$ apptainer build mynewimage.dir myimage.sif | |||
$ apptainer shell --writable mynewimage.dir | |||
Apptainer> # Run commands to update mynewimage.dir here. | |||
Apptainer> exit | |||
$ apptainer build newimage.sif mynewimage.dir | |||
$ rm -rf mynewimage.dir</source> | |||
Using an <code>SIF</code> image is recommended as disk performance (from the container image) will be faster than storing each file, etc. separately on Alliance cluster filesystems (which are set up to handle large files and parallel I/O). Using an <code>SIF</code> file instead of a sandbox image will also only use a quota file count amount of 1 instead of thousands (e.g., images will typically contain thousands of files and directories). | |||
===Building a Sandbox Directory=== | ===Building a Sandbox Directory=== |