Singularity: Difference between revisions

Jump to navigation Jump to search
Line 274: Line 274:
===Running a Single Command===
===Running a Single Command===


This section is incomplete and will be completed later.
When submitting jobs that invoke commands in Singularity containers, one will either use Singularity's <code>exec</code> or <code>run</code> commands.
* The <code>exec</code> command does not require any configuration.
* The <code>run</code> command requires configuring an application within a Singularity recipe file and is not discussed here.
 
The Singularity <code>exec</code> command's options are almost identical to the <code>shell</code> command's options, e.g.,
 
<source lang="console">$ singularity exec --help</source>
 
When not asking for help, the <code>exec</code> command runs the command you specify within the container and then leaves the container, e.g.,
 
<source lang="console">$ singularity exec -B /home -B /project -B /scratch -B /localscratch myimage.simg ls /</source>
 
which will output the contents of the root directory within the container. The version of <code>ls</code> is the one installed within the container!
For example, should GCC's <code>gcc</code> be installed in the myimage.simg container, then this command:
 
<source lang="console">$ singularity exec -B /home -B /project -B /scratch -B /localscratch myimage.simg gcc -v</source>
 
will output the version information of what is installed within the container whereas running at the normal Compute Canada shell prompt:
 
<source lang="console">$ gcc -v</source>
 
will output the version of GCC currently loaded on Compute Canada systems.
 
If you need to run a single command from within your Singularity container in a job, then the <code>exec</code> command will suffice.
Remember to [[#Bind Mounts|bind mount]] the directories you will need access to in order for your job to run successfully.


===Running Container Instances===
===Running Container Instances===
Line 282: Line 306:
===Bind Mounts===
===Bind Mounts===


This section is incomplete and will be completed later.
When running a program within a Singularity container, by default, it can only see the files within the container image and the current directory.
Realistically your Singularity jobs will need to mount the various filesystems where your files are. The is done using the <code>-B</code> option
to the Singularity <code>shell</code>, <code>exec</code>, or <code>run</code> commands, e.g.,
 
<source lang="console">$ singularity shell -B /home -B /project -B /scratch -B /localscratch myimage.simg</source>
<source lang="console">$ singularity exec -B /home -B /project -B /scratch -B /localscratch myimage.simg ls /</source>
<source lang="console">$ singularity run -B /home -B /project -B /scratch -B /localscratch myimage.simg some-program</source>
 
The previous three commands show how to bind mount the various filesystems on Compute Canada's systems, i.e., within the container image <code>myimage.simg</code> these commands bind mount:
* <code>/home</code> so that all home directories can be accessed (subject to your account's permissions)
* <code>/project</code> so that project directories can be accessed (subject to your account's permissions)
* <code>/scratch</code> so that the scratch directory can be accessed (subject to your account's permissions)
* <code>/localscratch</code> so that the localscratch directory can be accessed (subject to your account's permissions)
 
In most cases, it is not recommended to directly mount each directory you need as this can cause access issues. Instead mount the top directory for the file system as shown above.


==HPC Issues With Singularity==
==HPC Issues With Singularity==
cc_staff
156

edits

Navigation menu