Docker and Apptainer
To run a Docker image using Docker:
docker run -it --rm <image> command
where:
-it: Lets you interact with the container as if it was a shell--rm: Automatically remove the container when it exits.command: a command to run within the container, typicallybash
Mounting a local directory in the container for permanent storage can be achieved using the -v binding.
For example, this will make the local ~/mywork available in the container as /usr/local/mywork:
docker run -it --rm -v ~/mywork:/usr/local/mywork <image> command
Useful commands
The Dockerfile keyword CMD can point to a script that will run if the
Docker run command is not included.
The keyword ENTRYPOINT defines a script that will always run in the container, regardless
of whether the command flag is included.
The entrypoint can be overwritten at runtime with the option below (using sh as an example):
--entrypoint /bin/sh
To inspect an image:
docker image inspect <image>
Apptainer
Linux hosts have apptainer (formerly Singularity), which can be run similarly to Docker.
It uses a cache directory to store the images, so I suggest setting that cache to
a location with large disk capacity. In the following example /path/to/user/cache is used:
export sif_cache=/path/to/$USER/sif
and then:
export APPTAINER_CACHEDIR=$sif_cache/apptainer-cache
export APPTAINER_TMPDIR=$sif_cache/apptainer-tmp
export TMPDIR=$sif_cache/apptainer-tmp
apptainer exec --cleanenv --bind ~/mywork:/usr/local/mywork \
<image> command