25.2. Running Application Containers with Podman
Podman's command set deliberately mirrors the verbs container users already
know - pull, run, build, push - while its architecture differs
underneath: there is no daemon. Each podman invocation talks to the
kernel, the storage store, and the network stack directly, then exits.
That design is why rootless operation is Podman's normal mode rather than
an add-on, and why systemd - not a daemon's restart policy - is the natural
place to manage long-running containers, as Section 25.4 shows.
25.2.1. Installing Podman and Configuring Rootless Users
The core set provides the runtime, the image builder, the registry client used for inspection and copying, and the user-namespace mapping tools rootless mode depends on. On ctr1, as john:
$ sudo apt install podman buildah skopeo uidmap curl
The command prompts for confirmation and installs the packages and their
dependencies; Debian's recommendations pull in the rootless helpers
(passt for user-space networking, fuse-overlayfs as the fallback
storage driver) so no further package is needed for rootless use. Later
sections add their own tools where they are introduced: Docker and Compose
in Section 25.5, the registry utilities in Section 25.6, and the
system-container packages in Section 25.7. The versions this chapter was
exercised against, on ctr1 as root:
# dpkg-query -W podman buildah skopeo uidmap systemd-container debootstrap docker.io docker-compose podman-compose
buildah 1.39.3+ds1-1+b7
debootstrap 1.0.141
docker-compose 2.26.1-4
docker.io 26.1.5+dfsg1-9+deb13u1+b1
podman 5.4.2+ds1-2+b2
podman-compose 1.3.0-1
skopeo 1.18.0+ds1-1+b5
systemd-container 257.13-1~deb13u1
uidmap 1:4.17.4-2
Rootless configuration needs nothing beyond the subordinate ranges of
Section 25.1.3, which a current Debian account already has: the four
/etc/subuid and /etc/subgid entries listed there answer for the
mapping side, and podman info from Section 25.1.1 (true overlay
netavark systemd) answers for the runtime side. With both in place,
every operation in the rest of the chapter works from john's
unprivileged shell.
25.2.2. Image Registries, Tags, Digests, and Image Inspection
An image reference names three things: a registry, a repository within it,
and a version. docker.io/library/alpine:3.20 means the Docker Hub
registry (docker.io, also Podman's default when a name is left
unqualified), the library/alpine repository, and the 3.20 tag. Tags are
mutable labels - the latest tag moves with every release, and even a
version tag can be re-pointed by its owner. A digest is the immutable
alternative: the SHA-256 hash of the image's manifest, which lists its
config and layers by their own hashes. A reference like
alpine@sha256:c64c... names exact bytes, and every registry and client
in this chapter verifies them on transfer.
| Option | Description |
|---|---|
--tls-verify |
require verified HTTPS to the registry (default; made explicit in the registry examples) |
--authfile |
use a specific credentials file instead of the default login state |
--all-tags |
pull every tag of the repository, not just the named one |
--quiet |
suppress the per-blob progress report |
Pulling stores the image in john's rootless store. On ctr1, as john:
$ podman pull docker.io/library/alpine:3.20
Trying to pull docker.io/library/alpine:3.20...
Getting image source signatures
Copying blob sha256:25f1d6b1951ac8eb3740558fe94cb83d377bdadf95fd9f98b50d2e1b96130471
Copying config sha256:bf8527eb54c3680e728d5b4b383a8ba730d72dae7236fbc8dff97ed6b224a731
Writing manifest to image destination
bf8527eb54c3680e728d5b4b383a8ba730d72dae7236fbc8dff97ed6b224a731
podman pull contacts the registry even when the image is already local -
the copy from Section 25.1.1 is refreshed, not skipped - and prints the
image ID on the last line. The progress report names each blob by digest as
it copies, which is the content-addressed guarantee in action: the store
refuses to write data whose hash does not match the signed manifest.
| Option | Description |
|---|---|
--format |
print selected fields with a Go template instead of full JSON |
--type |
inspect an image (image), a container (container), or let the name decide |
Inspection reads the stored metadata without running anything. The architecture field matters on multi-arch hosts; the digest field is the pin a deployment should record. On ctr1, as john:
$ podman image inspect --format '{{.Id}} {{.Digest}} {{.Architecture}}' docker.io/library/alpine:3.20
bf8527eb54c3680e728d5b4b383a8ba730d72dae7236fbc8dff97ed6b224a731 sha256:c64c687cbea9300178b30c95835354e34c4e4febc4badfe27102879de0483b5e amd64
The first value is the image ID - the hash of its config; the second is
the registry's manifest digest, the identifier that stays constant across
hosts and that Section 25.6 uses to pin deployments. skopeo inspect
retrieves the same metadata from a registry without storing the image at
all, which is how a deployment host can check a tag's digest before
pulling.
25.2.3. Launching Containers and Inspecting Their State
The examples from here through Section 25.2.4 run the handbook-web
image: a small Alpine-based HTTP service built in Section 25.2.4 from
three files in the workspace. To follow the chapter in strict order,
create ~/debian-handbook/containers/webapp with the files shown there
and run its podman build command first, then return here; Section 25.2.4
explains what each instruction does.
podman run creates a container from an image and starts it. The options
used across this chapter:
| Option | Description |
|---|---|
-d, --detach |
run in the background and print the container ID |
--name |
give the container a stable name for later commands |
-p, --publish |
publish a port as [host-ip:]host-port:container-port |
-e, --env |
set an environment variable inside the container |
-v, --volume |
attach a bind mount or named volume |
--secret |
mount a Podman secret (Section 25.3.3) |
--network |
attach to a named container network (Section 25.3.1) |
--rm |
remove the container when it exits |
--read-only |
make the container's root filesystem read-only |
--tmpfs |
provide a writable tmpfs at a path |
--userns=keep-id |
map the invoking UID into the container unchanged |
--restart |
restart policy for unexpected exits |
--memory |
cgroup memory limit, e.g. 128m |
--cap-add, --cap-drop |
add or remove capabilities from the default set |
--privileged |
grant all capabilities and disable isolation limits |
A detached run with a published port and an environment variable is the shape most services take. On ctr1, as john:
$ podman run -d --name handbook-web -p 192.168.245.10:8080:8080 -e APP_MESSAGE='Hello from rootless Podman' localhost/handbook-web:1.0
6038136e28025753f040842b1c0076f907d7e3f92db19aa10a237ea2d8e1b9cc
The hex string is the new container's ID. The publish specification pins
the lab address explicitly - 192.168.245.10:8080 on the host forwards to
port 8080 in the container - because publishing on all addresses would
also expose the service on the management network. Rootless publishing is
performed by pasta, which forwards the connection in user space; nothing
in the host's firewall or port space is modified.
Inspection confirms the three settings in one line: state, identity, and the environment the process actually received. On ctr1, as john:
$ podman inspect --format '{{.State.Status}} {{.State.Running}} {{.Config.User}} {{range .Config.Env}}{{println .}}{{end}}' handbook-web | head -8
running true 10001:10001 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
container=podman
APP_MESSAGE=Hello from rootless Podman
HOME=/srv
HOSTNAME=6038136e2802
The {{range .Config.Env}} loop prints one variable per line, and
head -8 bounds the report. The image's USER 10001:10001 instruction is
in force - the service does not run as the container's root - and the
APP_MESSAGE variable arrived exactly as given. The container=podman
variable is set by the runtime so scripts inside the image can tell which
engine is running them.
The service should answer on the published address, both locally and from the independent client. On ctr1, as john:
$ curl -sS http://192.168.245.10:8080/
Hello from rootless Podman
On ctrclient, as john:
$ curl -sS http://192.168.245.10:8080/
Hello from rootless Podman
The second request proves the port is reachable from outside the host that runs the container, not merely looped back by the runtime - a distinction that Section 25.8.2 turns into a diagnostic procedure when publishing fails. Two further inspection commands round out the state picture. On ctr1, as john:
$ podman port handbook-web
8080/tcp -> 192.168.245.10:8080
$ podman inspect --format '{{.State.Health.Status}}' handbook-web
healthy
podman port reports the actual mapping, resolving any automatic port
selection. The health status comes from the HEALTHCHECK instruction
baked into the image (Section 25.2.4): right after startup the value
passes through starting and settles at healthy once the probe - an
HTTP request to the service itself - succeeds, so a starting result
simply means the first interval has not elapsed yet. Logs are the last
piece of the state picture. On ctr1, as john:
$ podman logs --tail 5 handbook-web
The command prints nothing here: this image's httpd does not write
access logs unless asked to, so the container has produced no output on
its standard streams. A quiet podman logs is a normal result, not a
failure; Section 25.4.3 shows where a service's logs go instead.
25.2.4. Building an Image with a Containerfile
A Containerfile describes an image as a short sequence of instructions,
each of which becomes one read-only layer stacked on the previous. Create
the three workspace files for the handbook-web service. First, the
served page, in ~/debian-handbook/containers/webapp/index.html:
Debian handbook web container
Second, the entrypoint, in ~/debian-handbook/containers/webapp/entrypoint.sh:
#!/bin/sh
set -eu
if [ -n "${APP_MESSAGE:-}" ]; then
printf '%s\n' "$APP_MESSAGE" > /srv/index.html
fi
exec httpd -f -p 8080 -h /srv
Third, the Containerfile itself, in
~/debian-handbook/containers/webapp/Containerfile:
FROM docker.io/library/alpine:3.20
ARG IMAGE_VERSION=1.0
LABEL org.opencontainers.image.title="handbook-web" \
org.opencontainers.image.version="${IMAGE_VERSION}" \
org.opencontainers.image.description="Small HTTP service for the Debian handbook"
RUN apk add --no-cache wget busybox-extras \
&& addgroup -g 10001 -S app \
&& adduser -u 10001 -S -G app -h /srv app
COPY index.html /srv/index.html
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod 0755 /usr/local/bin/entrypoint.sh \
&& chown -R app:app /srv
USER 10001:10001
EXPOSE 8080
HEALTHCHECK --interval=10s --timeout=3s --start-period=5s \
CMD wget -q -O /dev/null http://127.0.0.1:8080/ || exit 1
CMD ["/usr/local/bin/entrypoint.sh"]
| Option | Description |
|---|---|
-t |
tag the result, e.g. -t localhost/handbook-web:1.0 |
--build-arg |
set a variable for ARG lines in the file |
--format docker |
emit Docker-format metadata, required for HEALTHCHECK to survive the build |
-f |
name the Containerfile explicitly (default: Containerfile in the context) |
--no-cache |
rebuild every layer, ignoring cached results |
Build the image from the directory that holds the three files. On ctr1, as john:
$ cd ~/debian-handbook/containers/webapp && podman build --format docker --build-arg IMAGE_VERSION=1.0 -t localhost/handbook-web:1.0 .
STEP 1/11: FROM docker.io/library/alpine:3.20
STEP 2/11: ARG IMAGE_VERSION=1.0
--> 46147036fd4c
STEP 3/11: LABEL org.opencontainers.image.title="handbook-web" org.opencontainers.image.version="${IMAGE_VERSION}" org.opencontainers.image.description="Small HTTP service for the Debian handbook"
--> 71afb4db3e00
STEP 4/11: RUN apk add --no-cache wget busybox-extras && addgroup -g 10001 -S app && adduser -u 10001 -S -G app -h /srv app
fetch https://dl-cdn.alpinelinux.org/alpine/v3.20/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.20/community/x86_64/APKINDEX.tar.gz
(1/5) Installing busybox-extras (1.36.1-r31)
Executing busybox-extras-1.36.1-r31.post-install
(2/5) Installing libunistring (1.2-r0)
(3/5) Installing libidn2 (2.3.7)
(4/5) Installing pcre2 (10.43)
(5/5) Installing wget (1.24.5)
Executing busybox-1.36.1-r31.trigger
OK: 11 MiB in 19 packages
--> b78e63619c90
STEP 5/11: COPY index.html /srv/index.html
--> 812fb7d7a232
STEP 6/11: COPY entrypoint.sh /usr/local/bin/entrypoint.sh
--> 96e09b4e9d90
STEP 7/11: RUN chmod 0755 /usr/local/bin/entrypoint.sh && chown -R app:app /srv
--> d7b3e5c04dbd
STEP 8/11: USER 10001:10001
--> 6c72e4eef1b5
STEP 9/11: EXPOSE 8080
--> 978592d5d7f3
STEP 10/11: HEALTHCHECK --interval=10s --timeout=3s --start-period=5s CMD wget -q -O /dev/null http://127.0.0.1:8080/ || exit 1
--> 8d85e87cb512
STEP 11/11: CMD ["/usr/local/bin/entrypoint.sh"]
COMMIT localhost/handbook-web:1.0
--> fdd4551414df
Successfully tagged localhost/handbook-web:1.0
fdd4551414df382f9fb0ae62ed7fd354ac626dc04d92b17a651e69c5872b8523
Each STEP n/11 is one instruction and one layer; the indented lines under
step 4 are that layer's build output. The design choices worth noticing:
ARG IMAGE_VERSIONplus theLABELline stamp the image's version into its metadata, so any host can read what it is running without starting the container. Section 25.4.4 changes this one value to produce version 2.0.- The
RUNlayer creates a dedicated user (app, UID 10001) and installs only the two packages the image needs.USER 10001:10001then makes the service run as that unprivileged account - inside the container. Under rootless Podman the container's UID space is john's anyway (Section 25.1.1), so the service ends up doubly unprivileged. HEALTHCHECKis a Docker-format instruction. Podman's default build format is OCI, which has no health-check field, so the build passes--format dockerto keep the probe; without it the image builds but arrives without a health check.- The final
CMDnames the entrypoint, which rewrites the served page fromAPP_MESSAGEwhen that variable is set and thenexecs the web server.execmatters: it makeshttpdthe container's process 1, so the runtime's signals reach the server directly.
Verify the metadata the build stamped, in particular the version label and the user. On ctr1, as john:
$ podman image inspect --format '{{index .Labels "org.opencontainers.image.version"}} {{.Config.User}}' localhost/handbook-web:1.0
1.0 10001:10001
The image is now a local artifact in john's rootless store. Everything the service needs to run is in the image; everything that must survive it - pages, data, credentials - is deliberately outside, which is the subject of the next section.