Binding local folders (aka volumes)

You will sometimes need to bind additional host system directories into a container you are using over and above those bound by default. For example:

  • There may be a shared dataset in a shard location that you need access to in the container
  • You may require executables and software libraries in the container

The -B option to the singularity command is used to specify additonal binds. For example, to bind the /work/z19/shared directory into a container you could use (note this directory is unlikely to exist on the host system you are using so you’ll need to test this using a different directory):

singularity shell -B /work/z19/shared hello-world.sif
Singularity> ls /work/z19/shared

Note that, by default, a bind is mounted at the same path in the container as on the host system. You can also specify where a host directory is mounted in the container by separating the host path from the container path by a colon (:) in the option:

$ singularity shell -B /work/z19/shared:/shared-data hello-world.sif
Singularity> ls /shared-data
mkdir testdir
touch testdir/testout
singularity shell -e -B ./testdir:/scratch fastqc-0.11.9--0.sif
> touch /scratch/testin
> exit
ls -l testdir

You can also specify multiple binds to -B by separating them by commas (,).

You can also copy data into a container image at build time if there is some static data required in the image. We cover this later in the section on building Singularity containers

Paths of host system mounted in the container

For others, need to be done explicitly (syntax: host:container)