Skip to content

3. Apptainer Bind: Sharing Data Between Host and Container

Apptainer's bind feature allows users to map directories from the host system into the container environment. This is essential for reading or writing data, leveraging host-based filesystems, or sharing results from container jobs.​

How Binding Works

By default, Apptainer binds your home directory and current working directory into containers. You can also specify custom bind mounts using the --bind flag or the environment variable APPTAINER_BIND.​ Our recommendation is to use the latter option to bind the full BMRC file system

  • Set the APPTAINER_BIND variable before launching the container (useful for repeated binds).
export APPTAINER_BIND="/gpfs3/well,/gpfs3/users"

Making this bind Permanent

We recommend adding these environment variable to your ~/.bashrc file so they're automatically set for all future sessions

echo 'export APPTAINER_BIND="/gpfs3/well,/gpfs3/users"' >> ~/.bashrc

code

One time consumption binding:

apptainer shell --bind /path/to/host_folder1:/folder1,/path/to/host_folder2:/folder2 <apptainer-image>.sif

Best Practices

  • If the destination is omitted, Apptainer mounts the directory to the same path in the container (e.g., /project → /project).​

  • Paths must be absolute; relative paths are not accepted.

  • Use binds to access input/output data, reference scripts, or share results with the host system.

  • Bind mounts are a central aspect of making containers practical in HPC environments, facilitating seamless data movement between host and container