Apptainer: Difference between revisions

Jump to navigation Jump to search
Line 150: Line 150:
The <code>apptainer exec</code> command will launch an Apptainer container and directly run the command specified. Prefer using <code>apptainer run</code> command instead of using this command as <code>apptainer run</code> will run the container's <code>%runscript</code> which may be important for establishing the correct execution environment for the software in your container.
The <code>apptainer exec</code> command will launch an Apptainer container and directly run the command specified. Prefer using <code>apptainer run</code> command instead of using this command as <code>apptainer run</code> will run the container's <code>%runscript</code> which may be important for establishing the correct execution environment for the software in your container.


The use of the <code>apptainer exec</code> is identical to <code>apptainer run</code> except <code>exec</code> is specified instead of <code>run</code>. For example, suppose you want to run the <code>g++</code> compiler inside your container to compile a C++ program called <code>myprog.cpp</code>. This command might be used:
The use of the <code>apptainer exec</code> is identical to <code>apptainer run</code> except <code>exec</code> is specified instead of <code>run</code>. For example, suppose you want to run the <code>g++</code> compiler inside your container to compile a C++ program called <code>myprog.cpp</code> and then run that command. This command might be used:


  apptainer exec your-container-name.sif g++ -O2 -march=broadwell ./myprog.cpp
  apptainer exec your-container-name.sif g++ -O2 -march=broadwell ./myprog.cpp
apptainer exec your-container-name.sif ./a.out


where:
where:
Line 158: Line 159:
* <code>g++ -O2 -march=broadwell ./myprog.cpp</code> is the command you want to run inside the container
* <code>g++ -O2 -march=broadwell ./myprog.cpp</code> is the command you want to run inside the container


On our clusters, you will likely need to use a number of additional options (that appear after <code>run</code> and before <code>your-container-name.sif</code>). These options will include <code>-C</code>, <code>-c</code>, <code>-e</code>, <code>-W</code> as well as various bind mount options to make your disk space available to the programs that run in your container. For example, a more complete command might be:
On our clusters, you will likely need to use a number of additional options (that appear after <code>run</code> and before <code>your-container-name.sif</code>). These options will include <code>-C</code>, <code>-c</code>, <code>-e</code>, <code>-W</code> as well as various bind mount options to make your disk space available to the programs that run in your container. For example:


   apptainer exec -C -W $SLURM_TMPDIR -B /home -B /project -B /scratch your-container-name.sif g++ -O2 -march=broadwell ./myprog.cpp
   apptainer exec -C -W $SLURM_TMPDIR -B /home -B /project -B /scratch your-container-name.sif g++ -O2 -march=broadwell ./myprog.cpp
  apptainer exec -C -W $SLURM_TMPDIR -B /home -B /project -B /scratch your-container-name.sif ./a.out


For more information on these options see the following sections on this page:
For more information on these options see the following sections on this page:
cc_staff
156

edits

Navigation menu