Containers with Podman
Find, run and manage rootless containers with persistent storage and published ports.
By Invicly Tech, , in Linux Administration (RHCSA-style). About 10 minutes to read.
In short
Podman runs OCI containers without a central daemon and can run them rootless as a normal user. Its commands mirror Docker's: pull images, run containers with published ports and environment variables, and mount host directories for persistent data. On SELinux systems the :Z volume option relabels host directories so containers can use them.
Explained simply
A container packs an application with everything it needs, such as libraries and config, into one bundle. It runs the same on your laptop and on the server. It is not a full virtual machine: all containers share the host's kernel, so they start in a second and use little memory.
An image is the read-only template, like a recipe. A container is a running copy made from it. Images come from registries, online stores of images such as registry.access.redhat.com, quay.io or docker.io.
Podman is Red Hat's container tool. Its commands look just like Docker's, but it needs no background service, and normal users can run containers without root. If a container is hacked, the attacker is only your user, not root.
Containers are throwaway: delete one and its changes are gone. To keep data such as a database, you mount a folder from the host into the container. On RHEL, add :Z to that mount so SELinux lets the container use it.
Press Play on a diagram to walk through it one step at a time.
- 1podman CLI
No daemon; runs as your user.
- 2conmon
Small monitor process per container.
- 3OCI runtime (crun)
Creates the container process.
- 4Kernel features
User namespaces, cgroups, SELinux labels.
- 5Image storage
~/.local/share/containers for rootless users.
- Images
- search
- pull
- images
- build
- rmi
- Containers
- run
- ps -a
- stop / start
- rm -f
- Debugging
- logs -f
- exec -it
- inspect
- top
- Storage
- volume create
- volume ls
- unshare chown
In depth
Finding the right image
Always use full image names: registry, path and tag, such as registry.access.redhat.com/ubi9/httpd-24:latest. A short name like httpd makes Podman search the registries listed under unqualified-search-registries in /etc/containers/registries.conf, and it may prompt you or pick an image you did not expect, which is a security risk.
podman search httpd lists matches, and podman search --list-tags shows tags for one image. To read an image's details before pulling it, skopeo inspect docker://registry.access.redhat.com/ubi9/httpd-24 shows its labels, ports and environment. Red Hat's registry.redhat.io needs a login (podman login), while registry.access.redhat.com serves the free UBI images.
- podman images lists local images and their size
- podman image inspect IMAGE shows default command, ports and user
- Pin a tag or digest in production; latest changes over time
How rootless containers work
Rootless Podman uses a user namespace. Inside the container, a process may be root (UID 0), but outside it is mapped to your own user. Other UIDs inside the container map to a private range listed for you in /etc/subuid and /etc/subgid, usually 65536 IDs starting at 100000. useradd sets these up automatically.
This has visible effects. Files a container creates in a mounted folder may show strange owners like 100999 on the host. podman unshare chown 999:999 ~/data changes ownership as the container sees it, and the :U volume option does this automatically. Rootless containers also cannot bind host ports below 1024 by default, so publish 8080 instead of 80, or lower net.ipv4.ip_unprivileged_port_start.
- Process runs as UID 0 or 999
- Sees its own files under /
- Listens on port 8080
- Thinks it owns the machine
- UID 0 maps to your user
- UID 999 maps into your subuid range
- Port published with -p 8080:8080
- Storage in ~/.local/share/containers
Storage: volumes, bind mounts and SELinux
There are two ways to keep data. A bind mount maps a host folder: -v ~/db:/var/lib/mysql:Z. A named volume is managed by Podman: podman volume create dbdata, then -v dbdata:/var/lib/mysql. Named volumes are labelled correctly by Podman, so they need no :Z.
With bind mounts on SELinux systems, the container process runs as container_t and may not read ordinary host files. :Z relabels the folder with a private label just for this container. Lowercase :z uses a shared label so several containers can use it. Never use :Z on a system folder like /home or /etc: it relabels everything, and other services stop working. Make a dedicated folder instead.
- :Z private label, :z shared label, :U fix ownership
- :ro mounts read-only, e.g. -v ~/conf:/etc/app:ro,Z
- podman volume inspect dbdata shows where it lives
Running, debugging and cleaning up
podman run -d --name db -p 3306:3306 -e MARIADB_ROOT_PASSWORD=secret IMAGE starts a container in the background with a published port and an environment variable. Image documentation tells you which variables it needs. --rm deletes the container when it stops, which suits one-off commands.
When something fails: podman ps -a shows stopped containers and exit codes. podman logs NAME shows output, and -f follows it. podman exec -it NAME bash opens a shell inside a running container. podman inspect NAME shows everything, including mounts, IP and the command. podman stop, start and rm -f manage the lifecycle, and podman system prune removes unused containers and images.
Building an image from a Containerfile
A Containerfile (the same format as a Dockerfile) is a recipe. FROM picks a base image. RUN runs commands during the build, such as dnf install. COPY adds files from the build folder. EXPOSE documents a port. USER sets who the process runs as. CMD sets the default command. Each instruction creates a layer, and unchanged layers are reused from cache, so put rarely changing steps first.
Build with podman build -t myapp:1.0 . in the folder holding the Containerfile, or use -f to point at it. Keep images small: start from a minimal base like ubi9/ubi-minimal, clean the package cache in the same RUN line, and run as a non-root user. Push to a registry with podman push after podman login.
- 1Write Containerfile
FROM, RUN, COPY, USER, CMD
- 2podman build -t app:1.0 .
Each step becomes a cached layer
- 3podman images
app:1.0 is stored locally
- 4podman run -d -p 8080:8080 app:1.0
A container from the image
- 5podman push
Share it through a registry
Learn it in 5 short steps
About 50m each. Track them with a timer in your plan.
- 1Search and pull images from registries~50m
- 2Run containers with ports and env vars~50m
- 3Mount persistent storage with :Z~50m
- 4Inspect logs and exec into containers~50m
- 5Build an image from a Containerfile~50m
Key points
- Use fully qualified image names such as registry.access.redhat.com/ubi9/ubi.
- -p 8080:80 publishes a port; rootless containers cannot bind ports below 1024 by default.
- -v /host/dir:/data:Z mounts storage with a private SELinux label.
- podman logs, exec and inspect are the main debugging tools.
- Build images from a Containerfile with podman build.
Key terms
Tap a card to flip it. 0/6 known
Examples
podman search httpd
podman pull registry.access.redhat.com/ubi9/httpd-24
mkdir -p ~/web && echo hello > ~/web/index.html
podman run -d --name web -p 8080:8080 \
-v ~/web:/var/www/html:Z registry.access.redhat.com/ubi9/httpd-24
curl localhost:8080
podman ps; podman logs web; podman exec -it web bashRun a rootless web container serving files from your home directory.
A rootless MariaDB with persistent data
You need a database for testing that keeps its data across container restarts. Step 1: create a dedicated host folder. Step 2: run MariaDB with a name, a published port, the required environment variables, and the folder mounted with :Z. Step 3: check the logs until it says ready for connections. Step 4: remove the container and start a new one with the same mount; the database is still there.
mkdir -p ~/dbdata
podman run -d --name db -p 3306:3306 \
-e MARIADB_ROOT_PASSWORD=Secret123 -e MARIADB_DATABASE=shop \
-v ~/dbdata:/var/lib/mysql:Z docker.io/library/mariadb:11
podman logs -f db # wait for: ready for connections
podman exec -it db mariadb -uroot -pSecret123 -e 'SHOW DATABASES;'
podman rm -f db
# same command again: database shop still existsBuild and run a tiny web image
Step 1: create a folder with an index.html and a Containerfile based on the UBI httpd image, which listens on 8080 and runs as a non-root user. Step 2: build it with a tag. Step 3: run it, publishing 8080. Step 4: test with curl, then look at the image layers with podman history.
mkdir -p ~/site && cd ~/site
echo '<h1>Hello from Podman</h1>' > index.html
cat > Containerfile <<'EOF'
FROM registry.access.redhat.com/ubi9/httpd-24
COPY index.html /var/www/html/
EXPOSE 8080
EOF
podman build -t mysite:1.0 .
podman run -d --name mysite -p 8080:8080 mysite:1.0
curl -s localhost:8080
podman history mysite:1.0 | head -5Quick reference
- Use full image names: registry/path:tag, never a bare short name
- skopeo inspect docker://IMAGE reads image details without pulling it
- podman run -d --name N -p HOST:CTR -e KEY=VAL -v DIR:/path:Z IMAGE
- :Z private SELinux label, :z shared label, :U fix ownership for rootless
- Rootless containers cannot bind host ports below 1024 by default
- podman logs -f N, podman exec -it N bash, podman inspect N
- podman unshare chown 999:999 DIR changes ownership as the container sees it
- podman build -t name:tag . builds from ./Containerfile
Common mistakes
- Forgetting :Z, so SELinux blocks the container from reading the volume.
- Using short image names that resolve to an unexpected registry.
Quick quiz
Pick an answer to see if you're right and why.
Practice exercises
Try each one yourself first. Use the hint if you get stuck, then compare with the solution.
- Exercise 1easy
Pull the UBI 9 minimal image, run a one-off container that prints the OS release, and make sure it is removed afterwards.
- Exercise 2medium
Run the UBI httpd container serving ~/web on host port 8081, then find its IP, mounts and command with inspect.
- Exercise 3hard
Build an image that runs a Python HTTP server as a non-root user on port 8000, and prove the process inside is not root.
Check yourself
Answer in your head, reveal, then be honest with yourself.
Feel confident about this topic?
Frequently asked questions
- Is Podman compatible with Docker?
- Mostly yes. The commands and image format are the same, and many people simply alias docker to podman. The main differences are no daemon, rootless by default, and Quadlet for running containers as systemd services.
- Where are my rootless images and containers stored?
- In ~/.local/share/containers/storage. Each user has their own images, so root and other users do not see them.
- Why do files in my mounted folder have odd owners like 100999?
- They were created by a non-root user inside the container, which maps into your subuid range on the host. Use podman unshare to change them, or the :U volume option.
- What is the difference between :z and :Z?
- :Z gives the folder a private label that only this container can use. :z gives a shared label so several containers can use the same folder.