Hands-on #1
Accessing the Singularity image
A Singularity image of CentOS should be available in your home directory. Alternatively, CentOS Singularity container can be pulled from SingularityHub.
Singularity shell
Singularity shell allows you to interact with the container.
Singularity auto mounts your home directory, check if a file called test
is created in your home directory. If you want to keep the container’s environment contained, meaning no sharing of host environment, use --contain
Singularity exec
To run commands directly from a container, use singularity exec
:
To enable debugging, use --debug
flag
To launch the container as a separate process use -p
flag
Environments
Singularity passes the Host environment to the container.
Hint: Might need path of singularity, use
which singularity
to find the path for the last 2 commands.
Directory access
By default Singularity tries to create a seamless user experience between the host and the container. To do this, Singularity makes various locations accessible within the container automatically. For example, the user’s home directory is always bound into the container as is /tmp
and /var/tmp
. Additionally your current working directory (cwd/pwd
) is also bound into the container iff it is not an operating system directory or already accessible via another mount. For almost all cases, this will work flawlessly as follows:
Warning For directory binds to function properly, there must be an existing target endpoint within the container (just like a mount point). This means that if your home directory exists in a non-standard base directory like
/foobar/username
then the base directory/foobar
must already exist within the container. Singularity will not create these base directories! You must enter the container with the--writable
option being set, and create the directory manually.
Files on the host can be reachable from within the container
On a research cluster, you probably want to access locations with big datasets, and then write results too. For this, you will want to bind a folder to the container. Here, we are binding our local ./lammps
to /lammps
in the image, and listing the contents to show it worked. We use the command -B
or --bind
to do this.
Running LAMMPS code
LAMMPS is a popular Molecular Dynamics code, a Singularity image for LAMMPS code is available in the home directory. To execute the lammps
directory code:
To clone the lammps container
To run LAMMPS on Cambridge HPC
Writing in the container
While it is discouraged to make tweaks on the fly to containers (you should properly define all edits to the container in a bootstrap specification file, shown later) you can add --writable
to any command to write inside the container. Assuming we have our centos.img
on our local resource with sudo
, let’s try to make a /data
directory:
Info We would ideally have done this action with bootstrap, discussed next.
Last updated