Containerization & System Hardening with Podman
Created: 2026-11-05 · Last updated: 2026-11-13 · Nejat Hakan

Podman (Pod Manager) is a modern, daemonless, open-source Linux engine for developing, managing, and running OCI (Open Container Initiative) containers and Kubernetes-compatible Pods.
While keeping full CLI compatibility with Docker (alias docker=podman), Podman re-engineers container execution from the ground up: it eliminates the central root-privileged daemon and runs containers natively as unprivileged user processes (rootless) integrated directly into systemd.
1. Architecture: Why Daemonless & Rootless Matters
Traditional container engines rely on a monolithic background daemon (dockerd) running with full root privileges. If that daemon crashes, all child containers hang; if an attacker exploits a vulnerability in the daemon or breaks out of a container, they immediately gain root control over the host server.
Podman replaces the client-server daemon model with a traditional UNIX fork/exec architecture:
Architecture 1: Traditional Daemon Architecture (Docker)
%%{init: {'flowchart': {'wrappingWidth': 350}}}%%
flowchart TB
D_CLI["docker CLI"] ==>|"REST API"| D_Daemon["dockerd Daemon<br/>(Runs as root)"]
D_Daemon --> D_ContD["containerd"]
D_ContD --> D_Runc1["runc → Container A"]
D_Runc1 --> D_Runc2["runc → Container B"]
Architecture 2: Podman Fork/Exec Architecture (Rootless)
%%{init: {'flowchart': {'wrappingWidth': 350}}}%%
flowchart TB
P_User["Unprivileged User<br/>(UID 1000)"] ==>|"Direct fork/exec"| P_CLI["podman CLI"]
P_CLI --> P_Crun["crun (OCI Runtime)"]
P_Crun --> P_Conmon1["conmon → Container A<br/>(User Namespace)"]
P_Conmon1 --> P_Conmon2["conmon → Container B<br/>(User Namespace)"]
The Four Core Pillars of Podman
-
Rootless by Design
Containers run under regular user accounts utilizing Linux User Namespaces (
subuid/subgid). Evenrootinside the container maps to an unprivileged high UID on the host. -
Daemonless Fork/Exec
No background daemon eating RAM or acting as a single point of failure. Each container is monitored by a tiny C process (
conmon) and managed natively by the Linux kernel. -
Native Kubernetes Pods
First-class support for multi-container Pods sharing network (
localhost) and IPC namespaces—allowing seamless export to and import from Kubernetes YAML manifests. -
Systemd & Quadlet Integration
Containers run as native
systemdservices via declarative Quadlet units (.container,.pod,.network), complete withjournaldlogging and automatic registry rollbacks.
Technical Comparison: Podman vs. Docker
| Feature / Dimension | Podman (v5.x) | Docker Engine |
|---|---|---|
| Execution Model | Daemonless (fork/exec + conmon) |
Client-Server (dockerd + containerd) |
| Default Privilege Model | Rootless (First-class native citizen) | Rootful daemon by default (Rootless optional) |
| Default OCI Runtime | crun (Fast, lightweight C implementation) |
runc (Go implementation) |
| Systemd Integration | Native declarative Quadlets (systemd generator) |
Managed separately by dockerd restart policies |
| Multi-Container Unit | Native Pods + podman kube play + Compose |
Docker Compose / Swarm |
| CLI Compatibility | 100% drop-in compatible (podman run, build, ps) |
Standard Docker CLI |
2. Installation & Configuration Hierarchy
Podman is included in the official repositories of all major Linux distributions. For full rootless functionality, ensure user-namespace mapping (uidmap), rootless overlay filesystems (fuse-overlayfs), and user-space networking (passt / slirp4netns) are installed.
Pre-Flight Check: Subordinate UID/GID Mapping (subuid & subgid)
Rootless Podman requires a block of subordinate UIDs (typically 65,536 IDs) assigned to your Linux username in /etc/subuid and /etc/subgid:
Expected Output:
Missing subuid / subgid Entries?
If the command above returns nothing on a custom minimal server, allocate a 65,536 UID range to your user and migrate Podman's namespace mapping:
Configuration Files Precedence (TOML)
Podman reads configuration in a clean 3-tier hierarchy: Built-in Defaults → System Config (/etc/containers/) → User Overrides (~/.config/containers/).
-
containers.conf
Controls runtime behavior: default OCI runtime (
crun), network backend (netavark),cgroup_manager = "systemd", default timezone (tz = "local"), and default environment variables. -
storage.conf
Defines the storage driver (
overlay) and storage locations (graphroot):/var/lib/containers/storagefor root, and~/.local/share/containers/storagefor rootless users. -
registries.conf
Sets
unqualified-search-registries(e.g.,["docker.io", "quay.io"]), configures local pull-through mirror caches, or blocks untrusted registries. -
policy.json
Enforces cryptographic image signature verification rules (e.g., requiring GPG/Sigstore cosign signatures for production images).
Best Practice: Always Use Fully Qualified Image Names (FQIN)
Instead of typing podman pull alpine, always specify the exact registry domain: podman pull docker.io/library/alpine:latest. This prevents ambiguity prompts and protects against registry-squatting attacks.
Hands-On Lab 1: Inspecting Your Podman Environment & Creating a User Override
Run these commands as your normal, unprivileged user (no sudo!) to inspect your engine and configure automatic timezone synchronization for all your containers:
# 1. Inspect key engine paths and runtime backends
podman info | grep -E "graphRoot|ociRuntime|networkBackend|rootless:"
# 2. Create a user-level containers.conf that passes your host timezone into all containers
mkdir -p ~/.config/containers
cat << 'EOF' > ~/.config/containers/containers.conf
[containers]
tz = "local"
EOF
# 3. Verify by running an ephemeral Alpine container and checking its date/timezone
podman run --rm docker.io/library/alpine:latest date
3. Working with OCI Images & Multi-Stage Builds
Container images are immutable templates composed of read-only OverlayFS layers. When you start a container, Podman mounts a thin, ephemeral Read-Write (upperdir) layer on top of the read-only image layers (lowerdir).
Essential Image Management Commands
| Operation | Command Example | Purpose |
|---|---|---|
| Search | podman search --filter=is-official nginx |
Query registries for official repositories |
| Pull by Tag | podman pull docker.io/library/redis:7-alpine |
Download a specific version tag |
| Pull by Digest | podman pull alpine@sha256:beef... |
Pull an immutable cryptographic hash |
| List Images | podman images --digests |
Display local images, sizes, and SHA256 digests |
| Inspect Layers | podman image tree alpine:latest |
Visualize the layer hierarchy of an image |
| Prune Unused | podman image prune -a -f |
Reclaim disk space from unused images |
Building Production-Grade Images (Containerfile)
Podman uses Buildah under the hood to execute Containerfile (or Dockerfile) definitions. For production security, follow three rules:
1. Use minimal base images (alpine or distroless).
2. Drop privileges inside the image using a non-root USER instruction.
3. Combine RUN commands and clean package caches in the same layer.
Hands-On Lab 2: Building & Running a Hardened Custom Web Image
Let's build a minimal, custom Nginx container image from a Containerfile and verify its layer tree:
# 1. Create an isolated workspace
mkdir -p /tmp/podman-build-lab && cd /tmp/podman-build-lab
# 2. Create a custom landing page
cat << 'EOF' > index.html
<!DOCTYPE html>
<html>
<body style="font-family: sans-serif; background: #0f172a; color: #38bdf8; text-align: center; padding-top: 10%;">
<h1>🦭 Served by Rootless Podman!</h1>
<p>Built from a clean Containerfile using Buildah.</p>
</body>
</html>
EOF
# 3. Create the Containerfile
cat << 'EOF' > Containerfile
FROM docker.io/library/nginx:stable-alpine
LABEL maintainer="Nejat Hakan <nejat.hakan@googlemail.com>"
COPY index.html /usr/share/nginx/html/index.html
EXPOSE 80
EOF
# 4. Build the image and inspect its layer tree
podman build -t localhost/nh-web:v1 .
podman image tree localhost/nh-web:v1
# 5. Clean up workspace
cd ~ && rm -rf /tmp/podman-build-lab
4. Running & Managing Container Lifecycles
The podman run command creates and starts containers with fine-grained control over resource limits (cgroups v2), environment variables, and lifecycle policies.
podman run -d \
--name prod-api \
--memory="512m" \
--cpus="1.5" \
--read-only \
--tmpfs /tmp:rw,noexec,nosuid,size=64m \
-p 127.0.0.1:8080:80 \
localhost/nh-web:v1
-p 127.0.0.1:8080:80: Binds the port strictly to the host's loopback interface (so only a local reverse proxy like Nginx can reach it, rather than exposing port 8080 to the public internet).--memory="512m" --cpus="1.5": Enforces hardcgroups v2ceilings so a runaway container cannot starve the host OS.--read-only: Mounts the container's root filesystem as immutable, preventing attackers from modifying binaries if the web app is compromised.
Lifecycle & Debugging Cheat Sheet
# List running containers (add -a for stopped containers, --size for disk usage)
podman ps -a --size
# Stream real-time container logs since the last 10 minutes
podman logs -f --since 10m prod-api
# Display live CPU, RAM, and network I/O metrics (cgroups v2 top)
podman stats --no-stream
# Inspect processes running inside the container from the host perspective
podman top prod-api user,pid,hpid,comm
# Open an interactive shell inside a running container for debugging
podman exec -it prod-api /bin/sh
5. Podman Networking: Netavark, Pasta & Micro-Segmentation
Starting with Podman 4.0 and 5.0, networking was completely modernized using two high-performance tools:
- Netavark & Aardvark-DNS: A fast, Rust-based network stack that configures bridge interfaces,
nftables/iptablesrules, and automatic container-name DNS resolution (aardvark-dns). - Pasta (
passt): The modern rootless network backend (replacing the older, slowerslirp4netns). Pasta creates a high-speed Layer-2/Layer-4 translation tunnel without requiring root privileges.
Multi-Tier Network Isolation Architecture
In production, a public-facing frontend container should never share a network with all other containers on the host. Instead, create isolated custom networks so only authorized tiers can communicate:
%%{init: {'flowchart': {'wrappingWidth': 350}}}%%
flowchart TB
Internet(("Host :8080")) ==> Frontend["Frontend Container<br/>(Nginx)"]
subgraph FrontNet ["1. frontend-net (10.89.1.0/24)"]
direction TB
Frontend <==>|"DNS: http://backend"| Backend["Backend API<br/>(Dual-Homed)"]
end
subgraph BackNet ["2. backend-net (internal)"]
direction TB
Backend <==>|"DNS: postgres://db"| DB[("PostgreSQL DB<br/>(No Internet)")]
end
FrontNet ==> BackNet
frontendis attached only tofrontend-net. It cannot ping or reachdb.backendis attached to bothfrontend-netandbackend-net, acting as the sole gateway.backend-netis created with--internal, completely blocking outbound internet access from the database container.
Hands-On Lab 3: Enforcing Zero-Trust Network Segmentation
Build the exact 3-tier network topology shown in the diagram above and verify that the Frontend is mathematically blocked from reaching the Database:
# 1. Create the two isolated networks (backend-net has --internal = no internet)
podman network create frontend-net --subnet 10.89.1.0/24
podman network create backend-net --subnet 10.89.2.0/24 --internal
# 2. Launch Database (on backend-net ONLY) and Frontend (on frontend-net ONLY)
podman run -d --name db --network backend-net docker.io/library/alpine:latest sleep infinity
podman run -d --name frontend --network frontend-net docker.io/library/alpine:latest sleep infinity
# 3. Launch Backend connected to BOTH networks
podman run -d --name backend --network backend-net docker.io/library/alpine:latest sleep infinity
podman network connect frontend-net backend
# 4. Verify: Backend can resolve & ping DB (SUCCEEDS)
podman exec backend ping -c 2 db
# 5. Verify: Frontend CANNOT resolve or reach DB (FAILS with 'bad address')
podman exec frontend ping -c 2 db || echo ">>> SUCCESS: Frontend is strictly isolated from DB! <<<"
# 6. Clean up containers and networks
podman rm -f frontend backend db
podman network rm frontend-net backend-net
6. Persistent Storage: Named Volumes vs. Bind Mounts
Because a container's writable layer is destroyed when podman rm runs, stateful data (databases, uploads, certificates) must be stored outside the container using Named Volumes or Bind Mounts.
Managed entirely by Podman inside ~/.local/share/containers/storage/volumes/. Podman automatically fixes UID/GID ownership for rootless containers.
# 1. Create a volume and inspect its physical host path
podman volume create pg-data
podman volume inspect pg-data --format '{{.Mountpoint}}'
# 2. Mount the volume into a container
podman run -d --name postgres-db \
-v pg-data:/var/lib/postgresql/data \
-e POSTGRES_PASSWORD=StrongLabPassword \
docker.io/library/postgres:16-alpine
# 3. Clean up test
podman rm -f postgres-db && podman volume rm pg-data
Maps an arbitrary directory from your host filesystem into the container. Always append :ro for read-only configs, and :Z (private) or :z (shared) on SELinux systems.
Fixing Rootless Bind-Mount Permissions (podman unshare & :U)
If a container runs internally as a non-root UID (e.g., UID 999 for Postgres or UID 101 for Nginx), a host directory owned by your user (UID 1000) might reject writes.
Solution: Append the :U flag to the volume mount (-v ./data:/var/lib/data:Z,U). Podman will automatically chown the host folder to match the exact mapped user-namespace UID of the container!
7. Orchestrating Multi-Container Pods
Borrowed directly from Kubernetes, a Pod is a cohesive unit of containers that share the same Network, IPC, and UTS namespaces.
When you create a Pod, Podman spawns a tiny infra (pause) container whose sole job is to hold the network namespace open. Every application container added to the Pod shares the exact same IP address and communicates over ultra-fast localhost loopback:
%%{init: {'flowchart': {'wrappingWidth': 350}}}%%
flowchart TB
HostPort(("Host Port 8080")) ==>|"Forwarded"| Infra
subgraph Pod ["Pod: webapp-pod (10.88.0.x)"]
Infra["infra (pause) Container<br/>Holds Net/IPC Namespaces"]
Nginx["Container 1: Nginx<br/>Listens 0.0.0.0:80"]
App["Container 2: Backend API<br/>Listens 127.0.0.1:8000"]
Infra --> Nginx
Nginx <==>|"Loopback: :8000"| App
end
Hands-On Lab 4: Deploying a Reverse-Proxied Pod & Exporting to Kubernetes YAML
Notice how port forwarding (-p 8080:80) is declared once on the Pod, while the backend service and Nginx talk over localhost:
# 1. Create the Pod and publish host port 8080 -> Pod port 80
podman pod create --name demo-pod -p 127.0.0.1:8080:80
# 2. Start a simple Python HTTP backend inside the Pod on port 8000
podman run -d --pod demo-pod --name backend-svc \
docker.io/library/python:3.12-alpine \
python3 -m http.server 8000
# 3. Verify from INSIDE a second container in the same Pod that localhost:8000 responds!
podman run --rm --pod demo-pod docker.io/library/alpine:latest \
wget -qO- http://127.0.0.1:8000 | head -n 5
# 4. Bonus: Export this running Pod into a production Kubernetes YAML manifest!
podman kube generate demo-pod > /tmp/demo-pod-k8s.yaml
head -n 25 /tmp/demo-pod-k8s.yaml
# 5. Clean up the entire Pod in one atomic command
podman pod rm -f demo-pod && rm -f /tmp/demo-pod-k8s.yaml
8. Running Containers as Systemd Services (Quadlet)
In production, containers must start automatically on boot, restart on crashes, and log to journald.
Deprecation Notice: podman generate systemd → Quadlet
Starting with Podman 4.4 and 5.0, the imperative podman generate systemd command is officially deprecated. The modern, upstream standard is Quadlet—declarative systemd files (.container, .volume, .network, .pod) that systemd converts into native services on the fly.
Place declarative .container files in ~/.config/containers/systemd/ (rootless) or /etc/containers/systemd/ (rootful).
[Unit]
Description=Rootless Nginx Webserver managed via Podman Quadlet
After=network-online.target
Wants=network-online.target
[Container]
Image=docker.io/library/nginx:stable-alpine
ContainerName=nh-webserver
AutoUpdate=registry
PublishPort=127.0.0.1:8088:80
ReadOnly=true
Tmpfs=/var/cache/nginx /var/run
[Service]
Restart=always
TimeoutStartSec=300
[Install]
WantedBy=default.target
Activate and manage the Quadlet:
# 1. Enable lingering so rootless user services run at boot even without an active SSH login
sudo loginctl enable-linger $(whoami)
# 2. Generate the systemd unit dynamically and start the container
systemctl --user daemon-reload
systemctl --user start nh-webserver.service
systemctl --user status nh-webserver.service
# 3. Automatically pull new image releases and roll back on failure!
podman auto-update
For older Debian/Ubuntu systems running Podman < 4.4, you can still generate a traditional .service file from an existing container:
9. Defense-in-Depth: Rootless Security Architecture
Running rootless is the strongest defense against container breakouts, because UID 0 inside the container is mapped to your unprivileged UID on the host:
%%{init: {'flowchart': {'wrappingWidth': 350}}}%%
flowchart TB
subgraph ContainerNS ["1. Container Namespace"]
direction TB
C_Root["Container root<br/>(UID 0)"]
C_App["Container app<br/>(UID 101)"]
C_Root --> C_App
end
subgraph HostOS ["2. Host Permissions"]
direction TB
H_User["Host User (UID 1000)<br/>No Root Rights"]
H_Sub["Host SubUID (100100)<br/>Zero Host Access"]
H_User --> H_Sub
end
C_Root ==>|"UID Mapping"| H_User
C_App ==>|"SubUID Mapping"| H_Sub
ContainerNS ==> HostOS
The Five Layers of Podman Hardening
| Security Layer | Flag / Mechanism | Protection Provided |
|---|---|---|
| 1. User Namespaces | Rootless default (subuid) |
Maps container root to an unprivileged host user |
| 2. Linux Capabilities | --cap-drop=ALL |
Strips root powers (CAP_NET_RAW, CAP_SYS_ADMIN, etc.) |
| 3. No New Privileges | --security-opt=no-new-privileges |
Prevents processes from gaining privileges via setuid binaries |
| 4. Seccomp Filtering | Default /usr/share/containers/seccomp.json |
Blocks ~300+ dangerous kernel system calls (kexec, reboot, mount) |
| 5. Read-Only RootFS | --read-only |
Prevents attackers from writing backdoors or modifying container binaries |
Hands-On Lab 5: Proving the UID Mapping & Hardening a Container to the Extreme
Run this test to see with your own eyes that root (UID 0) inside the container is just your normal user (1000) on the host:
# 1. Check how UID 0 inside the container maps to your host UID in /proc/self/uid_map
podman run --rm docker.io/library/alpine:latest cat /proc/self/uid_map
# 2. Launch a container with ALL Linux capabilities dropped and an immutable filesystem
podman run --rm \
--cap-drop=ALL \
--security-opt=no-new-privileges \
--read-only \
docker.io/library/alpine:latest \
sh -c "id && grep CapEff /proc/self/status"
CapEff: 0000000000000000 proves that even though id outputs uid=0(root), the process has zero effective Linux kernel capabilities!
10. Troubleshooting & Common Pitfalls
1. Why can't my rootless container bind to Port 80 or 443?
Cause: By default, the Linux kernel forbids unprivileged users from binding to ports below 1024 (net.ipv4.ip_unprivileged_port_start = 1024).
Production Best Practice: Bind your rootless container to a high loopback port (-p 127.0.0.1:8080:80) and let your host's Nginx or Caddy reverse proxy handle public TLS on ports 80/443.
2. Why do my rootless containers stop when I log out of SSH?
Cause: Systemd terminates user sessions (and all child processes) when the last SSH session closes.
Fix: Enable systemd lingering for your user account:
3. Permission Denied on Bind-Mounted Host Directories
Cause: Either SELinux/AppArmor is blocking access, or the container runs as a non-root sub-UID (e.g., UID 999) that lacks write access to your host directory.
Fix: Append :Z,U to the volume flag (-v /host/path:/container/path:Z,U) so Podman applies the correct SELinux context and chowns the directory to the container's mapped UID.