5. Running a container, both interactively ( only the shell or inspect ) and via Slurm¶
Working with symlinked directories
If you are to access the apptainer image directory via a Symlink and execute the upcoming apptainer commands, it will trigger a warning similar to below
WARNING: Error changing the container working directory. Using '/users/....' instead: chdir /users/...: no such file or directory
The issue occurs because:
- Your shell resolves the symlink: When you
cd symlinkeddir/, your shell follows the symlink and your $PWD becomes/users/...(the symlink path) - Apptainer tries to bind the literal path: Apptainer attempts to set the working directory inside the container to match your current $PWD, but it's working with the symlink path
/users/... - The symlink doesn't exist inside the container: Even though you've bound the entire filesystem with
APPTAINER_BIND, the symlink itself may not be properly resolved or may not exist in the container's filesystem view
Solutions
-
Option 1: Always use the absolute paths
-
Option 2 : Use
cd -Pto resolve symlinks
-
To have a look at the contents of your container, you can "shell" into it using
Note - Above shell command will enter the shell within the container image. Note the prompt is now prefixed with "Apptainer", Exit the container by running the commandapptainer shell containername.exitwhich will bring you back to the host system -
To view metadata and configuration details about an Apptainer container image, use
apptainer inspect containername -
apptainer execcommand- The
apptainer execcommand allows you to run a specific command inside an Apptainer container, making it ideal for executing scripts, tools, or workflows within the container’s environment. For example, you can run a Python script or query the container’s filesystem without entering an interactive shell. Let't say you have a python script ( let's call it my_tensorflow.py) using Tensorflow libraries with a help menu and assuming you have Tensorflow container with all required libraries
- The
-
The apptainer
runcommand, on the other hand, is designed to execute the default process defined in the container (such as its runscript), providing a convenient way to start the container’s main application or service as intended by its creator. This is commonly used when you want to use the container as a standalone executable.
Slurm template
Accessing GPUs via Apptainer¶
Accessing GPUs via apptainer requires --nv flag
-
If your Slurm job has requested access to an NVIDIA GPU, an Apptainer container can transparently access it using the
--nvflag: -
For an example,