Starting podman containers on boot with systemd

Podman is pretty cool, and I have been playing around with it a bit recently.

Podman is essentially docker but without a daemon so it runs in userspace, and is developed by RedHat so it has nice things like Ansible integration, and is the driver behind Fedora’s Toolbox, a tool for Fedora Silverblue.

The podman blog says that you can start containers by creating an entry in /etc/systemd/system for every container that you want to start with the following example for Redis

Description=Redis Podman container
ExecStart=/usr/bin/podman start -a redis
ExecStop=/usr/bin/podman stop -t 10 redis

However, when I looked at Wireguard’s systemd service file as an example, I found a neater way to do it.

  • Create a new file /etc/systemd/system/podman@.service (the @ is the important part – be sure not to leave that out)
  • Add the following to the file:
Description=podman %I container

ExecStart=/usr/bin/podman start -a %i
ExecStop=/usr/bin/podman stop -t 2 %i

  • Stop (don’t rm) the container you want to run, and take note of its container name, eg: bitwarden_bitwarden_1
  • Start and enable the service with systemctl enable --now podman@container_name

I hope this helps someone out there 😀

  1. Also have a look at “podman generate systemd” …. the man page is podman-generate-systemd. This can automate this generation of systemd unit files.

Leave a Reply

Your email address will not be published.

%d bloggers like this: