Hello, here is how to run a rootless, persistent Podman container with systemd on RHEL 9. We'll use an official Docker Apache image for illustration purposes and user1 as a local, non-root user. This ensures that your Podman containers continue to run after a server reboot. Here we use podman generate systemd mechanism still valid on RHEL 9, whereas Red Hat recommends to consider Quadlets for future deployments (not covered here).
1. Prepare the user
dnf install -y container-tools
loginctl enable-linger user1
passwd user1
ssh user1@localhost
mkdir -p /webfiles
chown user1 /webfiles
2. Create a container
We use /webfiles directory to demonstrate how to mount it inside the container using Podman volumes (:Z handles selinux labels).
podman search httpd --filter=is-official
podman pull docker.io/library/httpd
podman tag docker.io/library/httpd apache
podman run -d --name web -p 8080:80 -v /webfiles:/var/www/html:Z apache
3. Generate a systemd service
mkdir -p ~/.config/systemd/user
cd ~/.config/systemd/user
The --name must match your container name "web" in this case
podman generate systemd --new --files --name web
Systemd service unit file is ready but you still have a running container, which must be removed
podman rm -f web
systemctl --user daemon-reload
systemctl --user enable --now container-web.service
4. Verify
After rebooting the server you should see your container in the running state, either with podman ps or from systemctl as below
reboot
systemctl --user status container-web.service
Congrats, you've successfully deployed a persistent, rootless Podman container as systemd service on RHEL 9!
Top comments (0)