Docker, singularity, apptainer

Table of Contents

1. Docker

1.1. Docker setup

1.1.1. Execute docker command with non-root user

Restart the system after executing the following commands.

sudo groupadd docker
sudo usermod -aG docker $USER

1.2. Important docker commands

Typically docker needs sudo access.

1.3. Docker list commands

Command Description
docker image list List docker images in current system.
docker ps Lists running containers. (ps = process status)
docker ps -a Lists running and excited containers.

1.4. Starting containers

Command Description
docker container run -it <image>:<tag> Starting image in iteractive mode
docker container run -it –runtime=nvidia –gpus all <image>:<tag> Above + accessing nvidia GPUs
docker start <container id> Starting stopped container
docker container run -v <host path>:<docker path> -it o

1.5. Attaching

Command Description
docker attach <container id> Attaching to running container.
docker exec -it <container id> bash Attaching another terminal to running container.
   

1.6. Removing

Command Description
docker rmi <image id> removes docker images
docker rm <container id> removes stopped container
docker system prune Removes all stopped containers

2. Apptainer

2.1. Converting docker to singularity

2.1.1. Pull + convert

apptainer pull <sif file> <docker hub link>

# Example:
apptainer pull cuda_12.6.3.sif docker://nvidia/cuda:12.6.3-cudnn-devel-ubuntu22.04

2.1.2. Convert local image

This involves (1) converting to tar file and (2) converting to sif file.

# First convert to tar file
docker save -o <name>.tar <image>
docker save -o mlev_39_tf260.tar 708d3b89ade9

# Build app container
apptainer build mlev_39_tf260.sif docker-archive://mlev_39_tf260.tar

2.2. Starting

Command Description
apptainer shell –nv <sif file> Start shell with nvidia driver library
   

Date: 2024-11-04 Mon 16:58

Created: 2025-07-05 Sat 00:00

Validate