This repository contains resources I use to create and run containers.
It is hosted here on GitHub and here on my institutional GitLab.
I use podman to create and manage images.
You can install the podman desktop client from the official website (cf. link above), which lets you use podman out of the box.
For a more lightweight experience, I instead choose to install just the podman command-line tools with homebrew:
brew install podmanThe containers technology relies on Linux-specific features. Besides, many containers are based on GNU/Linux images. Podman therefore needs a virtual machine (VM) to run containers on MacOS. To download such a virtual machine, run:
podman machine initYou will see that podman downloads a virtual machine from quay.io.
You need to do this step only once: podman will find the downloaded file next time you will need it.
However, once per session (ie. every time you log out or restart your computer), you need to start the VM with:
podman machine startEach directory in ./images corresponds to an image that can be built with podman.
By convention, the instructions to build an image are in a file named Containerfile. These files use the same syntax
as Docker files.
To build an image, go to the image's directory and run (choose any tag you like for your image):
podman build --format=docker -t $tag_of_the_image .This will build the image using the instructions in Containerfile for the architecture of the system where the
command was run (eg arm64 when run on MacOS with a Silicon chip). You can build an image for another architecture as
follows:
podman build --platform=linux/amd64 --format=docker -t $tag_of_the_image .A container is an instance of an image. You can run several separate containers initialized from the same image.
List available images:
podman image listRemove an image:
podman image rm $the_imageList running containers:
podman psList all containers (those that are running and those that are stopped):
podman ps -aRun a container from an image in none-interactive mode:
podman run $the_imageUse option --rm if you do not want the container to be in the list (podman ps -a) after it has finished running:
podman run --rm $the_imageUse the option -it to run a container in interactive mode:
podman run -it $the_imageRun a command through a container:
podman run $the_image $the_command $command_arg1 $command_arg2Remove a container from the list:
podman rm $container_nameMake tar file of existing image so that it can be transfered to another machine:
podman save -o $my_tar_file $the_imageI use pcocc on a supercomputer where it is already
installed and configured. I use it to run containers created from images that I prepared on a different machine and
that I saved as a tar file (cf documentation above). You can run pcocc or its more recent Rust re-implementation
pcoss-rs.
The first step is to import the image that will be used to spawn containers:
pcocc-rs image import docker-archive:$the_image_as_tar_file $tag_of_the_imageYou can list available images with:
pcocc-rs image listTo run a command through a container:
pcocc-rs run $tag_of_the_image $the_command $command_arg1 $command_arg2You must use -- before specifying the list of dashed options for your program, for instance:
pcocc-rs run $tag_of_the_image /bin/bash -- --norc -c "echo Hello World"Using the --norc option with /bin/bash is useful in environments where the host's home directory is mounted in the
container (we do not want bash to source the host's user's ~/.bashrc file).
-
The Dockerfile reference documents all the instructions that can be used in a Docker-like
Containerfile. -
The RedHat documentation on podman and containers is pretty nice.