Red HatAlex TaylorTutorial
Getting started with containers using Podman
Summary
Containers package an application with its dependencies into an isolated runtime that shares the host kernel, starting in seconds with less overhead than virtual machines. Podman is an open source engine for developing, running, and maintaining containers without root privileges or a background daemon. Container images are built from a Containerfile, which uses commands similar to a Bash script, and can be published to registries like Quay.io or Docker Hub. Running a container with Podman uses the podman run command, and data persistence requires volume mapping with the -v flag and the :z label on SELinux-enabled systems. Multi-container stacks can be managed declaratively with podman-compose using a YAML file, and automatic restart on boot requires enabling systemd lingering and the podman-restart service.
Context
Containers package an application with its dependencies into an isolated runtime that shares the host kernel, starting in seconds with less overhead than virtual machines. Podman is an open source engine for developing, running, and maintaining containers without root privileges or a background daemon.
Approach / What changed
Install Podman with dnf, write a Containerfile, run containers with podman run, manage multi-container stacks with podman-compose, and enable systemd lingering for automatic restart.
Takeaways
Podman runs containers without root privileges or a background daemon, reducing the risk of a single daemon crash taking down all containers.
Container images are built from a Containerfile and can be published to registries like Quay.io or Docker Hub for reuse across machines.
To persist data across container updates, mount a host directory with the -v flag and the :z label on SELinux systems before the first run.
FAQ
How do I update a running container?
Stop and remove the container, pull the new image, then run it again with the same volume mount and restart policy. For podman-compose, run podman-compose pull followed by podman-compose up -d --force-recreate.
How do I make a container start on boot?
By default, Podman is daemonless, so containers do not start on boot. Enable lingering for your user with loginctl enable-linger $USER, then enable the podman-restart service with systemctl --user enable podman-restart.service. The container must have its restart policy set to always.
How do I persist data across container updates?
Use the -v flag to mount a host directory into the container, for example -v ~/uptime-kuma-data:/app/data:z. The :z label is needed on systems with SELinux. The directory must exist before running the container, and the volume must be mounted from the start to preserve data across container recreations.
Source and freshness
- Source
- developers.redhat.com
- Published
- Added to Yomu
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.