Podman & Systemd

Systemd can be used to start and stop containers at boot and shutdown, respectively. This creates a scenario where no intervention is needed on a system reboot.

Before proceeding, be sure to enable linger for whichever user will be running the containers.

  • Enable linger for the user that will run the container.
loginctl enable-linger $USER
  • Create ~/.config/systemd/user to keep the user systemd unit files.
mkdir -p ~/.config/systemd/user

Creating systemd unit files for podman containers

  1. Run the container with all the mounts, ports, and env variables needed.

  2. Generate systemd unit file using podman generate command.

podman generate systemd --new --files --name $container_name
  1. Stop and remove the container.

  2. Move the service unit file to ~/.config/systemd/user.

mv -Z container-$container_name.service ~/.config/systemd/user/
  1. Reload the systemd daemon.
systemctl --user reload-daemon
  1. Enable and start the container using systemctl.
systemctl --user enable --now container-$container_name.service

Creating systemd unit files for podman pods

Creating a systemd unit file for a pod is the same as with a container. The only difference is that a systemd unit file will be created for each container that is a part of the pod.

  1. Run the pod and containers with all the mounts, ports, and env variables needed.

  2. Generate service file using podman generate command.

podman generate systemd --new --files --name $pod_name
  1. Stop and remove the pod and containers.

  2. Move all the unit files to ~/.config/systemd/user/

mv -Z pod-$pod_name.service container-* ~/.config/
  1. Reload the systemd daemon.
systemctl --user reload-daemon
  1. Enable and start the pod using systemctl. This will start all dependent containers as well.
systemctl --user enable --now pod-$pod_name.service

This site uses Just the Docs, a documentation theme for Jekyll.