Containers
What are containers
Containerization is a software deployment process that bundles an application’s code with all the files and libraries it needs to run on any infrastructure. It makes the application less dependent on the OS and system-wide installed libraries. A particular application packed together with its libraries and other files is a container. An image is a file sitting somewhere on the disk. A container is a runtime instance of an image.
Singularity is an open-source program for containerization used in MetaCentrum.
Singularity is invoked by the command singularity
.
Singularity images (= containers) are commonly suffixed by .sif
.
Singularity can import Docker images without having Docker installed or being a superuser
- see the Docker part.
Direct Singularity usage (new feature)
Singularity image can be added as PBS parameter
The Singularity image can now be specified directly upon job submission as a PBS parameter, and the container will be automatically launched when the job starts. This is a new feature (Aug 2024). Keep in mind that this new feature is still in testing mode, and probably some expansion and modifications (e.g. towards parallelized computing) will be still under way.
Key features:
- run the job as
qsub -v PBS_SINGULARITY_IMAGE=<singularity_image>
,<singularity_image>
is the location of image, e.g./cvmfs/singularity.metacentrum.cz/Metacentrum/debian11-openpbs.sif
docker://ubuntu:latest
- you can also pass the argument inside batch script as
#PBS -v PBS_SINGULARITY_IMAGE=<singularity_image>
/var/spool/pbs
and/etc/pbs.conf
are binded into the container automatically
Example
“bash`
I want to run Deb 11 OS from a container
Currently, the MetaCentrum OS is Deb 12
(BOOKWORM)user_123@tarkil:~$ lsb_release -a
No LSB modules are available. Distributor ID: Debian Description: Debian GNU/Linux 12 (bookworm) Release: 12 Codename: bookworm
run the job
(BOOKWORM)user_123@tarkil:~$ qsub -I -l select=1:ncpus=1 -l walltime=1:00:00 -v PBS_SINGULARITY_IMAGE=/cvmfs/singularity.metacentrum.cz/Metacentrum/debian11-openpbs.sif qsub: waiting for job 3696027.pbs-m1.metacentrum.cz to start qsub: job 3696027.pbs-m1.metacentrum.cz ready
Singularity> lsb_release -a No LSB modules are available. Distributor ID: Debian Description: Debian GNU/Linux 11 (bullseye) Release: 11 Codename: bullseye Singularity>
or
on the command line.
Run a command in the container
Passing a command to a Singularity image is done by singularity exec "command"
.
For example,
Open shell in container
You can also open a shell within a container to work interactively. This is done by singularity shell
command.
For example,
Do not use frontends for extensive containers' usage
Apart from light testing and learning, running containers right on frontends is equivalent to computing on frontend. This is strongly discouraged. For an extensive work with containers, use interactive or batch job.
Use container in an interactive job
First run interactive job with scratch directory:
What is the scratch directory good for?
You may need to redirect some Singularity environment variables to store temporary files. To point them to SCRATCHDIR
is one option. Alternatively you may redirect the Singularity variables to some folder in your home.
Run the container and open a shell within the container for interactive work:
Use container in bash job
As with any other software, it is possible to pass a batch script to a container, too.
Assume the batch script resides in /storage/city_N/home/user123/script.sh
.
Is the batch script for the Singularity application any different from the script for normal application?
In general, no, though for a very simple script, this may be the case. Most often, you will at least need to redirect Singularity environment variables to SCRATCHDIR
. The --bind
and bash -c
commands shown below may be hidden in the script, too.
Variant A: put Singularity-specific option on command line
Are you familiar with how the -B
(or --bind
) option in Singularity works?
The -B
option binds the location of your script in the grid directory onto /home/user123/
container directory.
Without the -B
option, the container will automatically bind to itself host directories on the computational node where the job is run and the script may not be found.
Variant B: hide Singularity-specific option into the script
Assume the batch script resides in /storage/city_N/home/user123/script.sh
AND that you want to have the CLI command as simple as possible.
In this case, run the batch job as
The script /storage/city_N/home/user123/script.sh
will then look somehow like the following:
Pre-built Singularity images
MetaCentrum offers a couple of ready-to-use Singularity images (.sif
files) together with batch scripts to run them.
These images are placed /cvmfs/singularity.metacentrum.cz/
.
Docker usage
Docker is just another type of container designed for single-user system that requires root priviliges.
For safety reasons, running Docker images directly is not possible on Metacentrum nodes.
If you need to use a Docker image in MetaCentrum, either
- run it in Singularity as described below, or
- use Kubernetes service.
Kubernetes service
Kubernetes is a Docker-specialized platform based on Kubernetes orchestrator.
In general, the platform can be used for almost anything, starting with a simple web application, to running a full remote desktop or a complex workflow pipeline.
Run in Singularity
If you have an existing Docker image, you can run it without root privileges in Singularity.
If you want to change something or make your own image from scratch, you’ll need root privileges; go to Kubernetes.
Prepare Singularity image from Docker image as:
Start docker image as:
Docker download instructions of the type
are in Singularity replaced as
This command will create circlator_latest.sif
, a singularity image of docker image.
Docker mounting command of the type
are in Singularity replaced by
where circ_read
is the folder used for getting data into an image. By running the command you are in the image and using df -h
you can check that the folder is mounted.
For more details see https://www.sylabs.io/guides/3.7/user-guide/singularity_and_docker.html.
Example
Let’s say you want to run Chronusq tool, an quantum chemical software package.
This is a small tool and can be compiled directly on the frontend. The resulting .sif
image will be about 166 MB large.
Alternatively, you can setup and interactive job and work from within the job.
First set path for temporary files:
(Default is /tmp
which has quota of only 1 GB.)
If you work within interactive job with scratch directory, then export SINGULARITY_TMPDIR=$SCRATCHDIR
is done automatically.
Next, download Docker image and build
After ca 5 minus the singularity image chronusq_latest.sif
will be ready.
To test the image, copy water molecule water.inp
from here:
and run the calculation of single-point ground state energy as
Advanced options
Custom Singularity build
Preparing your own Singularity image is intended for experienced users. Reading Singularity documentation is a good idea too.
To build custom image, root privileges are needed, but this can be replaced by User Namespace Remapping. For this purpose MetaCentrum offers a server builder.metacentrum.cz
with User Namespace Remapping.
Warning
Access to builder.metacentrum.cz
is not granted automatically. Users intending to build Singularity images have to apply for membership in group builders
by writing a request to meta@cesnet.cz.
Image file is read-only and to modify it you have to use sandbox directory. In this example we use Debian Buster docker image.
After running container from sandbox, you can make changes via package system, compile the source codes, install pip/conda modules etc. In this example we install ffmpeg package in Debian Buster environment.
It is necessary to work in the scratch directory, using fakeroot mode (-f
options) is not possible on storages (/storage/cityXY/...
).
After running container from sandbox, you can make changes via package system, compile the source codes, install pip/conda modules etc. In this example we install ffmpeg package in Debian Buster environment.
Build image from sandbox:
For the repeatable build of image you can use the definition file, example test1.def
Build image from recipe file:
For more details, see https://sylabs.io/guides/3.7/user-guide/definition_files.html.
Singularity parallelized job
The scenario for this setup is: two nodes with common scratch dir
Last updated on