liveBook · Manning

Podman generate systemd

As explained in Podman in Action: Secure, rootless containers for Kubernetes, microservices, and more

podman generate systemd --new is a Podman command that generates a systemd unit configured to create a container when the unit starts.

podman generate systemd --new generates a systemd unit that runs, stops, and removes a container instead of managing a pre-existing container. This avoids detached podman run commands that can make systemd misinterpret service completion. section 7.3.2 section 7.3.3

The generated unit coordinates the container lifecycle through systemd:

  • ExecStart runs the original image and container configuration through podman run, using a cidfile and systemd-oriented options such as --rm, --replace, and --sdnotify=conmon. section 7.3.3
  • ExecStop stops the container through its cidfile, while ExecStopPost removes it after shutdown. section 7.3.3
  • Reload the systemd user-unit database before starting the generated service with systemctl --user. section 7.3.2
  • Share the unit without first creating the container; starting it can pull the image and create a fresh container on another system. section 7.3.3

Generate and start a portable unit

podman generate systemd --new myapp > $HOME/.config/systemd/user/myapp-new.service systemctl --user daemon-reload systemctl --user start myapp-new systemctl --user status myapp-new section 7.3.3

Adding io.containers.autoupdate=registry enables podman auto-update to detect a changed registry image and restart the generated unit, which recreates the container from the updated image. section 7.3.4

How Podman in Action: Secure, rootless containers for Kubernetes, microservices, and more covers it

How deep it goes
Explains generated lifecycle commands, cidfiles, cleanup, portability, and auto-update, but does not detail systemd unit authoring internals.
Examples
Demonstrates myapp with port 8080, a generated user unit, systemctl lifecycle commands, and registry-backed image replacement.
What it assumes
Assumes a Podman container or image configuration and basic systemctl usage, while demonstrating user-unit generation and daemon reloads.
What you can do after
Operate containerized services through systemctl and distribute units that recreate containers from images without manual container creation.
How it connects
Connects Podman containers with systemd services, user units, container registries, and automatic image updates.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Podman in Action: Secure, rootless containers for Kubernetes, microservices, and more. The section links point to the parts of the book it draws on.