Manage podman with systemd

By gill, 3 January, 2023

After getting the containers running you can have systemd start and stop them for you.

$ podman pull docker.io/library/httpd

$ podman run -dt -p 8080:80/tcp --name httpd docker.io/library/httpd

Now you can create systemd files:

$ cd $HOME/.config/systemd/user

$ podman generate systemd --new --files --name httpd

The podman generate command creates a systemd service file named container-httpd.service. Reload the daemon to read the new file:

$ systemctl --user daemon-reload

Stop the running container

$ podman stop httpd

Start the container with systemctl

$ systemctl --user start container-httpd.service

Check if it's active

$ systemctl --user is-active container-httpd.service

active

Stop the container with systemctl

$ systemctl --user stop container-httpd.service

Persist your user settings so the container doesn't stop when you logout (because all the temporary files for your login get deleted.)

$ loginctl enable-linger $LOGNAME

Set systemctl to start the container on reboot

$ systemctl --user enable container-httpd.service
Private
Yes