Files and directories within a Singularity container#

Similar to docker Singularity also bind paths. Here bind is copying the files but making a symbolic link to the binded path. Therefore, any changes made inside the container to the binded path is preserved after clossing the container.

There is a default configuration of which files and directories are bound into the container. But it can be different depending on the system administrator.

Host system:                                                      Singularity container:
-------------                                                     ----------------------
/                                                                 /
├── bin                                                           ├── bin
├── etc                                                           ├── etc
│   ├── ...                                                       │   ├── ...
│   ├── group  ─> user's group added to group file in container ─>│   ├── group
│   └── passwd ──> user info added to passwd file in container ──>│   └── passwd
├── home                                                          ├── usr
│   └── jc1000 ───> user home directory made available ──> ─┐     ├── sbin
├── usr                 in container via bind mount         │     ├── home
├── sbin                                                    └────────>└── jc1000
└── ...                                                           └── ...

Binding additional host system directories to the container#

We can bind data as well as software to the container. We can use -B with singularity shell, singularity exec and singularity run.

Here we have binded /scratch/s.1915438/ to /binded_volume.

[s.1915438@sl2 test]$ singularity  shell -B /scratch/s.1915438:/shared_disk hello-world.sif
Singularity> ls /
apps  boot  environment  home  lib64  mnt  proc     root  sbin     shared_disk  srv  tmp  var
bin   dev   etc      lib   media  opt  rawr.sh  run   scratch  singularity  sys  usr
Singularity> ls /shared_disk/
Debugging Nvidia Modulus  Modulus_examples     SUT      ansys195         jupyter.sh      manim    parametrised_PINN  update.txt
Heat conduction FDM   Modulus_my_examples  Singularity  archive_name.tar.gz  jupyter_env.sh  modulus  requirements.txt
Modulus guides        Modulus_source       Untitled Folder  env          jupyter_log     outputs  temp
Singularity>

We can also bind multiple volumes using commas , without spaces.

[s.1915438@sl2 test]$ singularity  shell -B /scratch/s.1915438:/shared_disk,/scratch/s.1915438/modulus:/binded_modulus hello-world.sif
Singularity> ls /
apps  binded_modulus  dev      etc   lib    media  opt   rawr.sh  run   scratch  singularity  sys  usr
bin   boot        environment  home  lib64  mnt    proc  root     sbin  shared_disk  srv          tmp  var
Singularity> ls /binded_modulus/
bin  compiler_compat  conda-meta  etc  include  lib  lib64  pyvenv.cfg  share  ssl  x86_64-conda-linux-gnu  x86_64-conda_cos6-linux-gnu
Singularity> ls /shared_disk/
Debugging Nvidia Modulus  Modulus_examples     SUT      ansys195         jupyter.sh      manim    parametrised_PINN  update.txt
Heat conduction FDM   Modulus_my_examples  Singularity  archive_name.tar.gz  jupyter_env.sh  modulus  requirements.txt
Modulus guides        Modulus_source       Untitled Folder  env          jupyter_log     outputs  temp
Singularity>