Binding folders into your container
Objectives
Learn how you can bind folders into containers
When you launch a program in a container, the program runs in a contained environment. The file system in the container might not have the same folders structure as the machine that runs the container.
So, when you want to work on your data, you need to bring it with you into this contained world inside the container.
This is done via method called mount binding.
Binding means that a folder from the host system is mapped into a folder inside the container.
By default, $HOME
, $CWD
(current working directory)
/tmp
and
few other paths
are bound to the image.
If you want to do additional mappings you need to do it by giving an extra arguments to the command you’re running.
The following would bind folder /scratch
from the host system to
/scratch
in the container:
$ apptainer exec --bind /scratch example.sif ls /scratch
Setting --bind
-argument works for apptainer run
- and
apptainer shell
-commands as well.
You can also bind directories to different places. This is especially
helpful if, for example. the code in container expects that data
should be in /data
:
$ apptainer exec --bind /scratch:/data example.sif ls /data
Warning
Bind mounts are the same folders inside and outside of the image.
Deleting file from the folder that you bound inside the image will delete the file completely.
Key points to remember
By default only some folders are bound inside the container.
You’ll need to manually
--bind
-folders from outside of the container if you want to use them inside the container.Bound folders are the same folders inside and outside of the container.