Beyond controlling which host directories are included in the container, you may also want to ensure that specific folders are included and visible (mounted) inside the container, possibly with specific names. This is called binding, which means you are binding a host folder to a container path.

To bind a folder, you would use the --bind option. This option works with Apptainer's run, shell, and exec commands, plus others. The syntax is the location on your host computer, followed by a colon, then the path you want it mapped to inside the container. On the container side, you need to use an absolute path, but on the host side, the path can be relative to your current location. In the example below, a local data folder is mapped to /mydata inside the container using --bind:

Note that the mount point (/mydata in the example) is not required to exist in the container. But if it does, be careful because the container's folder will be replaced by the one on the host!

You can specify multiple --bind options to map different host directories (or even the same one) to different mount points in the container. You can also specify multiple mappings in a single --bind option as a comma-delimited list.

The --bind option has some additional configurations that are worth noting:

  • If you want to bind a host directory to the same absolute path inside a container, you may simply specify the absolute path on the host and omit the identical path inside the container. For example, --bind /scratch/10000/user/data will bind the entire /scratch directory on the host to /scratch in the container, so that all the directories under /scratch on the host are found in their expected places in the container, including /scratch/10000/user/data.
  • You may also want to specify that access to the host directory is read-only, which is done by appending :ro to the --bind specification. For example, --bind data:/mydata:ro will bind the host directory data to /mydata inside the container as a read-only directory. By default, access to the host directory will be both read and write.
 
©  |   Cornell University    |   Center for Advanced Computing    |   Copyright Statement    |   Access Statement
CVW material development is supported by NSF OAC awards 1854828, 2321040, 2323116 (UT Austin) and 2005506 (Indiana University)