NOTE: This was written while I was experimenting with using podman in lieu of docker, something I'm now looking at again. Not all docker images work with podman, so be prepared to struggle with the system and to engage in many fruitless Internet searches.
OK, so who knew podman containers won't automatically start on reboot? Yeah. Me neither.
Found out after a family member complained about getting a 500 error when trying to reach a PiGallery2 instance I had set up on the home server.
Fixing this is easy, as detailed in Pratham Patel's "How to Autostart Podman Containers?" over on Linux Handbook: A systemd service is created and enabled for each container.
What follows is my own summary of the steps Pratham sets out, modified for use in an environment where podman containers are owned and run by a nonprivileged user (in this case, "pods": see my One (non root) podman account to rule them all). Here, we'll use my "pigallery2" container as the target container.
- As root (or sudo root) enable lingering (
sudo loginctl enable-linger
). - Log in as the container user (
ssh pods@example
, simply doing an "su - pods" or "sudo su - pods will not suffice). - Shut down the container (
podman stop pigallery2
). - Create a systemd service for the container (
podman generate systemd --new --name "pigallery2" >pigallery2.service
). - Move the systemd file to the user's systemd service directory (
~/.config/systemd/user/
, if this doesn't exist create it). - Reload systemd for the user (
systemctl --user daemon-reload
). - Enable the service (
systemctl --user enable pigallery2
). - Reboot.
- Log back in as the container user and verify the container is running (
podman ps
). - Check service status (
systemctl --user status pigallery2
).
Prathan Patel. "How to Autostart Podman Containers?". Linux Handbook, 28 September 2022, https://linuxhandbook.com/autostart-podman-containers/.