Podman is an open-source, daemonless container engine designed for managing and running containers and pods. It is compatible with Open Container Initiative (OCI) standards, making it a versatile tool for containerized application development. Unlike Docker, Podman does not rely on a root-privileged daemon, enhancing its security and accessibility.
Podman has many key features. The two that caught my attention are:
- Daemonless Architecture: Podman eliminates the need for a root-privileged daemon, allowing containers to run as non-root users. This reduces security risks and makes it suitable for environments requiring strict privilege isolation.
- Rootless Containers: Users can create and manage containers without administrative privileges, ensuring better isolation and security.
The official Podman documentation has tutorials on the Basic Setup and Use of Podman in a Rootless environment. Honestly, I’ve never taken the time to fully understand user namespaces and how to map the UIDs and GIDs to the containers. Even articles such as this one by Daniel J Walsh didn’t provide an abundance of clarity. However, with lots of internet searches and help from AI, I have adopted a process that works for me.
The process I use flows something like this:
- Create a user account to be used by the container
- Connect to an interactive shell for the machine
- Create any required directories to store the container data
- Create the quadlets
- Start the container service
Here’s a look at these steps in more detail.
Create the user account for the container
The following commands are used to create the account, assign a password, and allow user processes to continue running even after the user logs out.
sudo useradd -c "username Container Account" -m username
sudo passwd username
sudo loginctl enable-linger username
Connect to the interactive shell
Using the machinectl shell command without arguments (thus invoking the executed shell or command on the local host), is in many ways similar to a su(1) session, but, unlike su, completely isolates the new session from the originating session, so that it shares no process or session properties and is in a clean well-defined state. It will be tracked in a new utmp, login, audit, security, and keyring sessions, and will not inherit any environment variables or resource limits, among other
properties.
sudo machinectl shell username
Create any required directories to store the container data
Following my process, the container image and configuration files are stored in the user’s home directory (also known as the login directory). To control the amount of disk space used by the container, I create a separate partition / mount point to be used as the user’s home directory. Those steps are outside this document.
mkdir -p ~/.config/containers/systemd
mkdir -p ~/containers/container_name
Create the quadlets
A Quadlet allows you to define container workloads declaratively using systemd-style configuration files including containers, pods, volumes, networks, and images. The content of these files can be found online.
vim ~/.config/containers/systemd/pod_name.pod
vim ~/.config/containers/systemd/container_name.container
Start the container service
Once the quadlet files have been created, simple start the service. It will be automatically restarted each time the system reboots. I also enable podman-auto-update.timer to ensure my containers are automatically updated. This is done for each user/container.
systemctl --user daemon-reload
systemctl --user list-unit-files | grep container_name
systemctl --user start container_name
That’s the gist of it. Hopefully this helps with your container journey.