Skip to main content

Containers (i.e. Docker/Singularity)

Containers are a useful way to take software produced on one system and make it portable so that it can run on another. A container image contains not only the application you wish to run, but also most of the operating system is was created on - everything apart from the kernel.

The most popular container system is called Docker, which is aimed at use on laptops and desktops. Unfortunately, Docker is unsuitable on a machine like Hamilton, but we instead provide a compatible system called Singularity.

This page has information about:

Running a Docker image using Singularity

As an example, this is how to download and run the ubuntu image from Docker Hub on one of Hamilton's login nodes:

$ singularity build ubuntu_latest.simg docker://ubuntu:latest
... skip some output ...
INFO:    Creating SIF file...
INFO:    Build complete: ubuntu_latest.simg

$ singularity shell ./ubuntu_latest.simg
Singularity> cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04.1 LTS"
Singularity>

Running jobs

Once you have downloaded an image to a file, you will be able to run the container in a job script.

The example job script below, my_container_job.sh, runs the copy of bash within the cached Ubuntu image, using a single CPU core:

#!/bin/bash

# Request resources:
#SBATCH -c 1          # 1 CPU core
#SBATCH --mem=1G      # 1 GB RAM
#SBATCH -t 1:0:0  # 1 hour (hours:minutes:seconds)

# Run in the default queue
# (job will share node with other jobs)
#SBATCH -p shared

# Commands to be run:
singularity run ./ubuntu_latest.simg /bin/bash -c "echo hello"

Submit this job to the queue with the command: sbatch my_container_job.sh