Containers & Podman
What Are Containers
Let's ask OpenAI: "Give me a high level explanation of containerization?"
Containerization is a method of deploying and running software applications in an isolated environment, known as a container.
Containers are lightweight and portable, allowing them to be easily moved between different computing environments. In containerization, the application and its dependencies are packaged together into a container image, which can be deployed to any environment that supports containerization.
Each container runs in its own isolated space, with its own set of resources, including memory, CPU, and storage. This isolation allows multiple containers to run on the same host machine without interfering with each other.
Containerization offers many benefits, including increased portability, scalability, and flexibility. It also simplifies the deployment process by providing a consistent environment for applications to run in, regardless of the underlying infrastructure. This makes it easier to develop, test, and deploy software applications quickly and reliably.
If you ask yourself, "Why would I need containers?", read this article : Do I need containers?
Where docker uses a daemon running as root, podman can/must be run as a non-priviledged user.
The Department of Computer Science has chosen podman as main container technology, because:
- It's FOSS
- It's daemonless
- It's rootless
podman is meant to be a safe drop-in replacement for docker: just replace the command 'docker' with 'podman' - all command line arguments should be understood in the same way.
For more details on podman go to: podman.io.
Because podman is running as a non-priviledged user, however, some extra care must be taken regarding where to put data and configuration. As our departmental accounts are making use of home directories over NFS, additional steps are needed, to get you started on a departmental machine.
Getting Started
So you want to get started using podman on a departmental machine?Log into the machine you want to run podman on with the account you want to run it with.
Execute:
/usr/local/cs-adm/bin/check-my-podman-configAdd the
--gpuargument if the machine has GPU cards and you want to use them in your containers.
Add the--verboseargument to see what is actually checked.If your podman configuration is not OK, do as is suggested there.
Old way of checking, not needed any more:
Am I already set up for using podman on this machine?:- Is podman installed? If you see a similar output, podman is installed.
$ apt policy podman podman: Installed: 100:3.4.2-5 Candidate: 100:3.4.2-5 Version table: *** 100:3.4.2-5 500 500 http://apt-cacher.cs.kuleuven.be:3142/podman-kubic-fossa Packages 100 /var/lib/dpkg/statusIf you see the below output, it is not.$ apt policy podman N: Unable to locate package podman
- Do I have a subuid/gid range for my containers?
Find your $UID: $ getent passwd | grep <$USERNAME> <$USERNAME>:*:<$UID>:..... Check if it is setup in /etc/subuid or /etc/subgid Don't forget to change <$USERNAME> and <$UID> with your actual username and uid! $ egrep "^(<$USERNAME>|<$UID>):" /etc/subuid
If the last command does not give any output, your account is not yet setup for use with podman on this machine.
- Do I have a dedicated location for my images?
If you don't have your own dedicated storage location where you want/need to put your images/volumes, you might be able to store them on the local disk of the machine where you want to run the container(s). That default local location to store them is:/export/home1/NoCsBack/containers/<$USERNAME>
If the following command does not give any output, your storage location is not yet setup for use with podman on this machine:
Either create it or find out where else to store the container images.
Don't forget to change <$STORAGELOCATION> with your actual storage location!$ ls -al <$STORAGELOCATION>
- Have I already used podman (possibly on a different machine) with this account?
If the previous steps are all successful, you are only one more step away from using podman.
Check whether podman is configured to use your container storage location:
Don't forget to change <$UID> and <$STORAGELOCATION> with actual values!$ vi ~/.config/containers/storage.conf and add or change contents to look like: [storage] driver = "overlay" runroot = "/tmp/<$UID>/storage" rootless_storage_path = "<$STORAGELOCATION>" [storage.options.overlay] mount_program = "/usr/bin/fuse-overlayfs" mountopt = "nodev,metacopy=on"
When this looks correct, you are set to go. Scroll down to see some command examples.- If your podman configuration is OK, then initialise your podman environment with:
Old, not needed any more: Request podman usage:
-
So in one of the checks above you noticed you are not set up to use podman on that machine.
-
Send email to helpdesk@cs.kuleuven.be
- In case you are requesting to install podman on a departmental machine, put the responsible for that machine in CC. Check here for contacts in your research group.
- Which machine ?
- Which account name ?
- Ensure your storage.conf file is set in your home directory. (see "Have I already used podman on a different machine with my account?")
-
Send email to helpdesk@cs.kuleuven.be
- Initialise your subuid ranges in your podman environment with:
$ podman system migrate
You can/should double-check with:$ podman unshare cat /proc/self/uid_map 0 20264 1 1 2131617 65536If you only see the first line, there is still something wrong.
- Let your containers run without a login session with:
$ loginctl enable-linger $UID
This is needed if you want containers to start at boot or stay running after logout.
Non-root Rootless Containers
The whole idea of podman is that you can run containers as an unprivileged user, without needing sudo-rights or a daemon running as root. But it doesn't just stop there: the process running inside the container should be ran as non-root user as well. If processes running as root inside the container can break out of the container, they are run as the (unprivileged) user that is running the container. As such they can access everything that user has access to, so possibly also other containers or credentials etc. By running the processes inside containers also with non-root accounts, you prevent that kind of access as well.
For this to work, the account that is running the container should have additional UIDs and GIDs available in /etc/subuid and /etc/subgid.
Documentation
Your favorite search-engine most probably has some links to excellent podman introductions.
Some example podman commands:
podman run ...: start a containerpodman stop container-ID: stop the containerpodman ps -a: see all (running and stopped) containerspodman rm container-ID: remove the containerpodman images: see all available imagespodman rmi image-ID: remove the imagepodman volume ls: see all available volumespodman volume rm volume-ID: remove the volumepodman system df: see a summary of containers, images and volumespodman pod ps: see all (running and stopped) podspodman pod stop pod-ID: stop the podpodman pod rm pod-ID: remove the pod{container|image|volume|pod}-IDcan be-awith which all {container|image|volume|pod}s are stopped or removed
In general, online help is available using the -h argument - this works on the top (podman -h), command (podman images -h) and sub-command level (podman volume ls -h).
Podman uses some directories to store information in: run-time state, images, ... It uses default locations in /tmp, /var or home directory. It might be best to keep things clearly visible and explicitly configure podman where to put these things, so that migrating to a different platform or version might be easier (because no platform-defaults are used then). You can/should do so with the --root and --runroot options. Experience shows, however, that if you want to use other tools like podman-compose, using the default directories might be necessary anyway.
Containers are often built from a docker-compose YAML file - there is (currently) no built-in support for those recipes in podman yet, but there is a github project that does just that: https://github.com/muayyad-alsadi/podman-compose. Some (very basic) usage information is shown on https://medium.com/faun/using-podman-with-docker-compose-files-b606f964b65.
There is also the companion command buildah that allows to create/manipulate containers that subsequently can be started with podman.
TODO
Because there is no global daemon overseeing the containers, the podman containers are not started automatically at (re)boot. Special configuration might be needed: either as an @reboot crontab of the podman user(s) or as an /etc/cs-localservices entry. Ask helpdesk for more information when needed.
Podman has a limited form of persistency: the first time you use the podman command after a (re)boot of the system, a podman process will keep running in background. During that first invocation, a warning about the OCI runtime is shown - it seems harmless and subsequent invocations of podman don't show it anymore. The background process seems to keep some state in the /run/user/UID/ directory.

