Containers package an application alongside all its dependencies into an isolated runtime. Because they share the host kernel instead of virtualizing an entire operating system, containers spin up in seconds with a fraction of the overhead of traditional virtual machines.
With containers, you can:
- Spin up new infrastructure in seconds without polluting your host environment
- Tear down and redeploy test instances with zero leftover artifacts
- Package an application once and run it consistently across Fedora, Red Hat Enterprise Linux (RHEL), or personal lab hardware
What is Podman?
In this topic article, Red Hat explains that Podman is an open source engine designed to let you develop, run, and maintain containers across Linux environments without requiring root privileges or a background daemon.
If it's not already installed on your system, you can install it using dnf:
dnf install podmanWhen I was first introduced to containers in 2019, they completely changed the way I ran services, both in my homelab and later as a system administrator. To this day, I always check that a project has a container before even considering installing it directly on a host.
How are Podman container images created?
Podman container images are built from something called a Containerfile. This file contains the commands used to create a container image. You may notice the syntax looks similar to a Bash script.
# Example of a Containerfile
FROM alpine
RUN apk add --no-cache figlet
ENTRYPOINT ["figlet", "Hello, world!"]Once created, a Podman image can be published, which means that image can be used on any number of machines when it's pulled down from a container registry, such as Quay.io or Docker Hub.
Running a container
For this example, I use the popular open source project Uptime-Kuma. Here's a simple example of how easy it can be to get started running a container:
podman run -d --name uptime-kuma -p 3001:3001 \
docker.io/louislam/uptime-kuma:2-d: Runs the container in "detached" mode-p: Publishes port 3001 on your machine to port 3001 in the containerdocker.io/louislam/uptime-kuma:2: The image name in the format of registry/namespace/repository:tag
However, because no volumes are mounted, if you recreate the container (such as during an upgrade, where you pull down a new image), you will lose your data.
You need a volume mapping (-v) to mount a source folder from your host machine to the container (an example command for this is shown in the next section).
By default, Podman is daemonless. This has the benefit of not being one monolithic service. If Podman had one single monolithic daemon, and that daemon crashed, it could take down every container with it.
Updating a container created on the command line
To update a container, stop and remove the container. Then pull the new updated image and run it (make sure the appropriate volume mount is added). For example:
podman stop uptime-kuma
podman rm uptime-kuma
podman pull docker.io/louislam/uptime-kuma:2
podman run -d \
--name uptime-kuma \
-p 3001:3001 \
--restart always \
-v ~/uptime-kuma-data:/app/data:z \
docker.io/louislam/uptime-kuma:2Notice that for this command, I use volume mapping. Before doing this, ensure the directory is already created, and the :z label is added if running on a machine with SELinux (for example, RHEL, Fedora, and so on). This also assumes you had this mounted on the container before updating. Mounting a volume like this after the fact doesn't copy the files!
Running a container with podman-compose
The podman-compose command provides a simple way to run containers declaratively using YAML. Install it with dnf:
dnf install podman-composeSome people prefer to structure applications into multiple containers running alongside one another, rather than trying to fit technically unrelated applications into a single container. Because each container is defined by a YAML file, you can manage your infrastructure with a good version control system, like Git.Some people find it easier to understand, and better to run, with stacks of multiple containers, such as using a database alongside a main container. They can also be managed with version control, such as Git.
Save this as podman-compose.yml in your project directory:
services:
uptime-kuma:
image: docker.io/louislam/uptime-kuma:2
restart: always
container_name: uptime-kuma
volumes:
- ~/uptime-kuma-data:/app/data:z
ports:
- "3001:3001"Run it using podman-compose:
podman-compose up -dUpdating a container created with podman-compose
You can update a container using podman-compose in just 2 commands. First, ensure you're in the project directory, then pull the new image (replacing the tag as necessary) and recreate it!
podman-compose pull
podman-compose up -d --force-recreatePersistence
Because Podman is daemonless, a container doesn't start on boot by default. Instead, you can enable "lingering" and then use the podman-restart service to automatically start containers. When you set a user's systemd to linger on boot, you allow systemd to manage containers as that user:
loginctl enable-linger $USERTo enable the podman-restart service, which starts a container according to its restart policy, use systemctl:
systemctl --user enable podman-restart.serviceA container managed this way is started according to its restart policy, so make sure it's set to always. A container doesn't start on boot with its default value of no.
Further reading
There are yet more ways to use containers. Here are some other methods to check out:
- Podman Desktop
- Cockpit lets you manage your containers from a web UI
- Podman Quadlets uses systemd to manage each of your containers
- My personal favorite is using Red Hat Ansible Automation Platform to manage and deploy Podman Quadlets
Get started with Red Hat OpenShift
Red Hat Training and Certification provides comprehensive curriculum designed to empower both new and experienced professionals in OpenShift. If you're new to containers, start with our no-cost Red Hat OpenShift for Developers Technical Overview (DO088) on-demand video. Once you've mastered the basics, you're ready to take the next step with Red Hat OpenShift Development I: Introduction to Containers with Podman (DO188).