Migrate from Docker to Podman on Linux: Daemonless Rootless Containers and Systemd Integration

DevOps tutorial - IT technology blog
DevOps tutorial - IT technology blog

Quick Start: Dropping Podman into Your Workflow

Switching from Docker to Podman takes less than five minutes. Because Podman adheres strictly to Open Container Initiative (OCI) standards, it accepts identical CLI flags, pulls standard Docker images, and requires no background daemon chewing up RAM.

Grab the binary from your distribution’s package repositories:

# Ubuntu 22.04 / Debian 12
sudo apt update && sudo apt install -y podman

# RHEL 9 / AlmaLinux / Rocky Linux
sudo dnf install -y podman

Keep your existing muscle memory intact. You can alias the command in your shell or install the official compatibility shim:

# Option 1: Official compatibility package
sudo apt install -y podman-docker   # Debian/Ubuntu
sudo dnf install -y podman-docker       # RHEL/Rocky

# Option 2: Shell alias
echo "alias docker=podman" >> ~/.bashrc
source ~/.bashrc

Spin up an unprivileged Nginx container to verify the installation:

docker run -d --name quick-web -p 8080:80 docker.io/library/nginx:alpine
curl -I http://localhost:8080

No background service started. No sudo required. Check ps aux | grep nginx on your host—those container processes run directly under your standard unprivileged UID.

Deep Dive: Architecture & The Rootless Paradigm

Docker relies on a monolithic client-server model. The client sends REST API commands over a Unix socket (/var/run/docker.sock) to dockerd, which runs as root. This creates a glaring single point of failure: anyone with socket access effectively controls root on the host machine.

Podman discards this model entirely in favor of a traditional Unix fork-exec approach. When you run podman run, Podman executes directly as your user and calls an OCI runtime like crun or runc. The runtime spawns the container as an immediate child process, making container processes trackable just like standard command-line tools.

How Rootless User Namespaces Work

Rootless isolation leverages Linux user namespaces along with subordinate UID and GID ranges defined in /etc/subuid and /etc/subgid. Distributions automatically assign a 65,536-ID block to standard user accounts upon creation:

grep $USER /etc/subuid
# Output:
# deployer:100000:65536

This configuration translates container permissions cleanly:

  • Container UID 0 (root) maps directly to your host UID (e.g., 1000).
  • Container UID 1 maps to host UID 100000.
  • Container UID 2 maps to host UID 100001.

If an attacker escapes a process running as UID 0 inside the container, they land on the host with zero root privileges—they are trapped inside the permissions of user 1000.

Binding Privileged Ports Below 1024

By default, the Linux kernel prevents unprivileged users from binding to ports lower than 1024. If your container needs to expose port 80 or 443 directly, lower the unprivileged port threshold:

sudo sysctl -w net.ipv4.ip_unprivileged_port_start=80
echo "net.ipv4.ip_unprivileged_port_start=80" | sudo tee -a /etc/sysctl.d/99-podman.conf

For networking, Podman links user-space traffic via pasta (the high-performance default on modern releases) or slirp4netns, bypassing the need for root-level virtual ethernet bridges.

Production Integration: Systemd Units & Auto-Updates

Without a background daemon to monitor crashed containers or trigger restarts on reboot, Podman hands lifecycle management to Linux’s native init system: systemd. This eliminates custom watchdog scripts and integrates container logs straight into journalctl.

Managing Containers with Systemd Quadlets

While legacy workflows used podman generate systemd, modern Podman (v4.4+) manages containers natively using Quadlets. Quadlets are declarative unit files parsed directly by systemd at startup.

Create your user systemd directory and declare your service:

mkdir -p ~/.config/containers/systemd/

Write the service definition to ~/.config/containers/systemd/redis.container:

[Unit]
Description=Production Redis In-Memory Cache
After=network-online.target

[Container]
Image=docker.io/library/redis:alpine
ContainerName=redis-prod
PublishPort=6379:6379
Volume=redis-data:/data:Z
AutoUpdate=registry
Exec=redis-server --appendonly yes

[Install]
WantedBy=default.target

Reload the systemd user daemon and start your container:

systemctl --user daemon-reload
systemctl --user enable --now redis.service
systemctl --user status redis.service

Enabling User Lingering

Linux terminates user-level systemd processes the moment you log out of an SSH session. Prevent this behavior and keep services running across reboots with lingering:

loginctl enable-linger $USER

Automated Container Updates and Rollbacks

With AutoUpdate=registry set in your Quadlet, Podman periodically pulls the latest matching image from your registry. If the new image fails its container health check, Podman rolls back to the previous image automatically:

# Trigger an immediate update check
podman auto-update

# Enable the scheduled systemd update timer (runs daily at midnight)
systemctl --user enable --now podman-auto-update.timer

Practical Migration Gotchas

1. SELinux Volume Mount Permissions (:Z vs :z)

RHEL, Fedora, and Rocky Linux enforce SELinux access controls on mounted host directories. If your container throws a Permission denied error on a bind mount, append the appropriate label flag:

# Exclusive access (relabel storage privately for this container only)
podman run -d -v /srv/site:/var/www/html:Z nginx

# Shared access (allow multiple containers to read/write this path)
podman run -d -v /srv/shared:/var/log/app:z my-app

2. Fixing File Ownership with podman unshare

When an internal container process (such as a MySQL container using UID 999) writes to a bound host directory, the file appears owned by host UID 100998. Avoid the bad habit of running chmod 777. Instead, enter the container’s user namespace using podman unshare:

# Inspect actual mapped permissions from within the namespace
podman unshare ls -ld /srv/mysql-data

# Chown files directly to the internal UID/GID target
podman unshare chown -R 999:999 /srv/mysql-data

3. Running Docker Compose Stacks Under Podman

You do not need to rewrite your multi-container stacks. Podman provides a socket-activated API service that speaks the Docker engine protocol, letting official docker compose work without modification:

# Start Podman's rootless API socket
systemctl --user enable --now podman.socket

# Point docker compose to the user runtime socket
export DOCKER_HOST="unix://${XDG_RUNTIME_DIR}/podman/podman.sock"

# Deploy existing compose stacks
docker compose -f docker-compose.yml up -d

4. Organizing Multi-Container Apps into Pods

Podman brings Kubernetes pods to single Linux machines. All containers placed in a shared pod share network interfaces, port mappings, and IP addresses, allowing services to talk securely over localhost:

# 1. Create the pod and expose port 80 to the host
podman pod create --name webapp-pod -p 8080:80

# 2. Attach the backend service to the pod
podman run -d --pod webapp-pod --name api-backend internal-api:1.0

# 3. Attach a reverse proxy that routes traffic to http://127.0.0.1:5000
podman run -d --pod webapp-pod --name web-proxy nginx:alpine
Share: