Containers and Kubernetes · Intermediate · 15 min
Run Podman containers as systemd services with Quadlet
By Padding · Updated 18 Nov 2026
Ubuntu 26.04 · Podman 5.7.0 · systemd 259
You will run PostgreSQL 18 under systemd from three short Quadlet files, with its password in a Podman secret, a health check that restarts it, daily image updates and its logs in the journal.
On this page
podman run -d starts a container, but nothing brings it back after a reboot, nothing restarts it when it hangs, and its logs live outside the journal you read for every other service. Quadlet fixes that. You write a short file that describes the container, and a systemd generator that ships with Podman turns it into an ordinary .service unit every time systemd reloads. From then on you manage the container with systemctl and journalctl, like any other service on the box.
You will build a small database service from three files: a network, a volume and a PostgreSQL 18 container. Its password comes from a Podman secret, not the unit file. A health check kills the container when PostgreSQL stops answering, so systemd restarts it, and a timer pulls a newer image when one is published. At the end you will run a container as your own user, without root, that keeps running after you log out.
Ubuntu 26.04 ships Podman 5.7.0 in the universe archive, and the Quadlet generator comes in the same package. Work through the steps in order: the generator only reads files, so you can check every unit it would make before any container starts.
Step 1 · Install Podman and find the generator
Install Podman from the Ubuntu archive:
sudo apt-get update
sudo apt-get install -y podman
podman --versionQuadlet is not a separate command you run. systemd runs every program in its generator directories early at boot and on each systemctl daemon-reload, and Podman installs one there:
ls -l /usr/lib/systemd/system-generators/podman-system-generatorFor root, the generator reads Quadlet files from /etc/containers/systemd/. That is where your files go. Create it:
sudo mkdir -p /etc/containers/systemdCheck it worked
podman --version prints podman version 5.7.0, and ls shows the generator file (usually a symlink to Podman's quadlet binary). If ls says the file does not exist, the install did not finish; run the apt-get install line again and read its errors.
Step 2 · Describe a network and a volume
Each Quadlet file type has its own extension. A .network file becomes a Podman network, and a .volume file becomes a named volume. Both are created by small one-shot services before any container that uses them starts.
sudo tee /etc/containers/systemd/app.network > /dev/null <<'EOF'
[Network]
Subnet=10.89.10.0/24
EOF
sudo tee /etc/containers/systemd/pgdata.volume > /dev/null <<'EOF'
[Volume]
Label=app=quadlet-demo
EOFThe file names matter more than their contents. Quadlet names things after the file:
app.networkbecomes the serviceapp-network.serviceand the Podman networksystemd-app.pgdata.volumebecomespgdata-volume.serviceand the Podman volumesystemd-pgdata.
Ask the generator what it would make, without writing anything:
sudo /usr/lib/systemd/system-generators/podman-system-generator --dryrunCheck it worked
The output has a ---app-network.service--- block whose ExecStart runs podman network create for systemd-app, and a ---pgdata-volume.service--- block that runs podman volume create for systemd-pgdata. Run this to confirm both names are there:
sudo /usr/lib/systemd/system-generators/podman-system-generator --dryrun > /tmp/quadlet-dryrun.txt
grep -q 'network create.*systemd-app' /tmp/quadlet-dryrun.txt; echo "network: ok"
grep -q 'volume create.*systemd-pgdata' /tmp/quadlet-dryrun.txt; echo "volume: ok"Both lines print ok. If either name is missing, grep fails and nothing more prints. If the generator prints an error such as unsupported key, it names the file and line to fix.
Step 3 · Store the database password as a Podman secret
The password must not sit in a unit file, which any user can read with systemctl cat. Podman keeps secrets in its own store and hands them to a container as a file. Generate a random password and pipe it straight into the store, so it never appears in your shell history or the process list:
openssl rand -base64 24 | tr -d '\n' | sudo podman secret create pg-password -
sudo podman secret lsThe - tells podman secret create to read the value from standard input. If you need to know the password later (to connect a client from another machine), save it to a password manager first: Podman will not show the value again unless you ask for it with podman secret inspect --showsecret.
Secrets created with sudo belong to root's Podman. A rootless container, run as your own user, cannot see them; your user has its own secret store.
Check it worked
podman secret ls lists one secret called pg-password with the file driver. Nothing in the output shows the password itself.
Step 4 · Write the PostgreSQL container unit
A .container file has a [Container] section for Podman's settings, and ordinary systemd sections for the rest. Write db.container:
sudo tee /etc/containers/systemd/db.container > /dev/null <<'EOF'
[Unit]
Description=PostgreSQL 18 for the Quadlet demo
[Container]
Image=docker.io/library/postgres:18-alpine
Network=app.network
Volume=pgdata.volume:/var/lib/postgresql
PublishPort=127.0.0.1:5432:5432
Secret=pg-password
Environment=POSTGRES_PASSWORD_FILE=/run/secrets/pg-password
HealthCmd=pg_isready -U postgres
HealthInterval=30s
HealthRetries=3
HealthStartPeriod=20s
HealthOnFailure=kill
AutoUpdate=registry
[Service]
Restart=always
TimeoutStartSec=300
[Install]
WantedBy=multi-user.target
EOFWhat each part does:
Network=app.networkandVolume=pgdata.volume:...point at the other two files by name. Quadlet swaps insystemd-appandsystemd-pgdata, and addsRequires=andAfter=lines so the network and volume exist before the container starts. PostgreSQL 18 images keep their data under/var/lib/postgresql, so the volume mounts there.PublishPort=127.0.0.1:5432:5432makes the database reachable from the server itself only. Leave out127.0.0.1:only if other machines must connect, and firewall it if you do.Secret=pg-passwordmounts the secret at/run/secrets/pg-passwordinside the container, andPOSTGRES_PASSWORD_FILEtells the image to read the password from there.HealthCmdrunspg_isreadyevery 30 seconds. After three failures in a row the container is unhealthy, andHealthOnFailure=killstops it. systemd sees the service die andRestart=alwaysstarts it again.AutoUpdate=registrymarks the container forpodman auto-update, which you set up later. It only works with a fully qualified image name like the one above.TimeoutStartSec=300gives the first start time to pull the image. The default 90 seconds can run out on a slow or metered connection.[Install]works as if you had runsystemctl enable: the generator wires the unit intomulti-user.targetitself. Generated units cannot be enabled withsystemctl enable.
On a prepaid or metered connection, pull the image once while you are on a cheaper link (sudo podman pull docker.io/library/postgres:18-alpine), so the first start does not download it.
Check it worked
Look at the service the generator builds from your file:
sudo /usr/lib/systemd/system-generators/podman-system-generator --dryrun > /tmp/quadlet-dryrun.txt
sed -n '/^---db.service---/,/^---/p' /tmp/quadlet-dryrun.txtThe ExecStart line is one long podman run. Confirm the settings you care about made it in:
grep -qE 'network[ =]systemd-app' /tmp/quadlet-dryrun.txt; echo "network: ok"
grep -q 'systemd-pgdata:/var/lib/postgresql' /tmp/quadlet-dryrun.txt; echo "volume: ok"
grep -qE 'health-on-failure[ =]kill' /tmp/quadlet-dryrun.txt; echo "health: ok"
grep -q 'io.containers.autoupdate=registry' /tmp/quadlet-dryrun.txt; echo "auto-update: ok"
grep -q 'pgdata-volume.service' /tmp/quadlet-dryrun.txt; echo "dependency: ok"All five lines print ok. If a setting did not reach the unit, its grep fails and the lines after it do not print; check the matching key in db.container and run the dry run again. The check is worth repeating after every edit.
Step 5 · Check the generated units with systemd-analyze
The dry run shows what Quadlet makes. systemd-analyze verify checks that systemd accepts it. --generators=true runs the generators first, so you can check the units before you reload anything. It can exit 0 while still printing warnings, so read the output rather than the exit code:
sudo systemd-analyze --generators=true verify db.service 2>&1 | tee /tmp/quadlet-verify.txt
if grep -E 'db\.service|pgdata|app-network' /tmp/quadlet-verify.txt; then echo "Fix the lines above"; false; else echo "No problems found in the Quadlet units"; fiCheck it worked
The last line reads No problems found in the Quadlet units. If you see a line such as db.service: Failed to parse ..., it names the setting; fix it in db.container, not in the generated unit, which is rebuilt on every reload.
Step 6 · Start the service and read its logs
Reload systemd so the generator runs, then start the database:
sudo systemctl daemon-reload
sudo systemctl start db.service
systemctl status db.service --no-pagerThe first start pulls the image, which can take a minute. You do not need to start app-network.service or pgdata-volume.service yourself; db.service pulls them in. Do not run systemctl enable db.service: the [Install] section has already done that, and enable refuses generated units.
The container's output goes to the journal, under the service name:
journalctl -u db.service -n 20 --no-pager
sudo podman ps --format '{{.Names}} {{.Status}}'Now try the health check and the restart. podman healthcheck run runs the check once by hand. Then stop PostgreSQL inside the container without stopping the container, and watch what happens:
sudo podman healthcheck run systemd-db && echo healthy
sudo podman exec -u postgres systemd-db pg_ctl stop -m fast -D /var/lib/postgresql/18/dockerStopping the server process ends the container's main process, so systemd restarts it at once. A hung database that stays up but stops answering is the case the health check catches: after three failed checks, 30 seconds apart, the container is killed and restarted the same way.
Check it worked
systemctl status shows active (running), and podman ps lists systemd-db with Up ... (healthy) once the start period has passed. The journal shows database system is ready to accept connections. After the pg_ctl stop, journalctl -u db.service shows the stop followed by a new start, and systemctl status shows active (running) again with a recent start time.
Step 7 · Turn on automatic image updates
Podman ships a service and a timer that run podman auto-update, which checks every container marked AutoUpdate=registry. When the registry has a new image for the same tag, it pulls it and restarts the unit. If the new container fails to start, it rolls back to the previous image. Look at the timer Podman installed:
cat /usr/lib/systemd/system/podman-auto-update.timerSee what an update would do now, without changing anything, then turn the timer on:
sudo podman auto-update --dry-run
sudo systemctl enable --now podman-auto-update.timer
systemctl list-timers podman-auto-update.timer --no-pagerThe 18-alpine tag moves to each new PostgreSQL 18 minor release, which is what you want for security fixes. It never moves to PostgreSQL 19, whose data format needs a planned upgrade. On a metered connection, leave the timer off and run sudo podman auto-update yourself when you are on a cheaper link; it only downloads layers that changed.
Check it worked
The timer file has an OnCalendar= line (daily on current builds). podman auto-update --dry-run lists db.service with the image name and an UPDATED column of false or pending. systemctl list-timers shows a NEXT time for podman-auto-update.timer.
Step 8 · Run a rootless container that survives logout
You do not need root to use Quadlet. A user's Quadlet files live in ~/.config/containers/systemd/, and the units run under that user's own systemd instance. Write a small web server for your user, on a port above 1024:
mkdir -p ~/.config/containers/systemd
tee ~/.config/containers/systemd/site.container > /dev/null <<'EOF'
[Unit]
Description=Static site on port 8080 (rootless)
[Container]
Image=docker.io/library/nginx:1.30-alpine
PublishPort=127.0.0.1:8080:80
AutoUpdate=registry
[Service]
Restart=always
[Install]
WantedBy=default.target
EOFdefault.target is the user instance's equivalent of multi-user.target. Check what the generator makes for your user with --user:
/usr/lib/systemd/system-generators/podman-system-generator --user --dryrun | grep -A3 -- '---site.service---'A user's systemd instance normally stops when their last session ends, and takes the container with it. Lingering keeps it running from boot, logged in or not:
sudo loginctl enable-linger "$USER"
systemctl --user daemon-reload
systemctl --user start site.service
curl -s http://127.0.0.1:8080 | grep -o '<title>.*</title>'
journalctl --user -u site.service -n 5 --no-pagerFor updates, the user instance has its own timer: systemctl --user enable --now podman-auto-update.timer.
Check it worked
The dry run prints a ---site.service--- block. After the start, curl prints <title>Welcome to nginx!</title>, and loginctl show-user "$USER" --property=Linger prints Linger=yes. Log out, log back in, and systemctl --user status site.service still shows the start time from before.
To remove everything this tutorial made, stop the units, delete the files and reload:
systemctl --user stop site.service
rm ~/.config/containers/systemd/site.container
systemctl --user daemon-reload
sudo loginctl disable-linger "$USER"
sudo systemctl stop db.service
sudo rm /etc/containers/systemd/db.container /etc/containers/systemd/pgdata.volume /etc/containers/systemd/app.network
sudo systemctl daemon-reloadRemoving the files does not delete the data. Warning: the next two commands delete the database volume and the password for good. Run them only if you want the data gone:
sudo podman volume rm systemd-pgdata
sudo podman secret rm pg-passwordNext steps
- Run rootless containers with Podman explains the user namespaces and subordinate IDs behind the rootless unit in the last step.
- Run your app as a systemd service covers the
[Unit],[Service]and[Install]settings you can add to any.containerfile. - Sandbox a systemd service with security options shows how to score and tighten a unit with
systemd-analyze security. - Replace cron jobs with systemd timers explains
OnCalendar=and how to change when the auto-update timer runs, with a drop-in.
Related tutorials
- Validate Kubernetes manifests before they reach a clusterYou will have one script that checks plain, Kustomize, Helm, generated and custom-resource manifests against the Kubernetes 1.37 schemas and a set of lint rules, with no cluster, and a GitHub Actions job that runs it on every pull request.
- Use secrets in Docker builds without leaking them into the imageYou will find a token and a private key leaking through a Docker build with Trivy 0.76, then fix the build with secret and SSH mounts, carry the fix into Compose and GitHub Actions, and prove with a rescan that the build context is clean.
- Store data in Kubernetes with persistent volumes and claimsYou will claim storage on a Kubernetes 1.37 kind cluster, prove the data outlives its pod, see which access modes and reclaim policies keep or lose data, and know how expansion and snapshots work on a cloud CSI driver.
Need this done for you?
Padding does this work for growing companies, from the first diagnosis to a system that keeps working.
Get new tutorials