Apptainer: Difference between revisions

Line 120: Line 120:
The <code>apptainer run</code> command will launch an Apptainer container, runs the <code>%runscript</code> defined for that container (if one is defined), and then runs the specific command (subject to the code in the <code>%runscript</code> script). Using this command is preferred over using the <code>apptainer exec</code> command (which directly runs a command within the specified container).
The <code>apptainer run</code> command will launch an Apptainer container, runs the <code>%runscript</code> defined for that container (if one is defined), and then runs the specific command (subject to the code in the <code>%runscript</code> script). Using this command is preferred over using the <code>apptainer exec</code> command (which directly runs a command within the specified container).


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>. To this this you might use this command:
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 program. To this this you might use this command:


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


where:
where:
Line 128: Line 129:
* <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 run -C -W $SLURM_TMPDIR -B /home -B /project -B /scratch your-container-name.sif g++ -O2 -march=broadwell ./myprog.cpp
   apptainer run -C -W $SLURM_TMPDIR -B /home -B /project -B /scratch your-container-name.sif g++ -O2 -march=broadwell ./myprog.cpp
  apptainer run -C -W $SLURM_TMPDIR -B /home -B /project -B /scratch ./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