Automatically Start Rootless Podman Containers on Boot
Table of Contents
I’m a big fan of Podman Quadlets, but sometimes I just stick with a Docker Compose file to test certain services and leave them running. The best part? Now I can do that with Podman too.
A lot of people don’t realize this, but Podman actually handles container restarts perfectly. If you have the restart: always option set in your compose file, Podman will bring those containers back up automatically after a reboot.
To get this working for a rootless setup, all you have to do is grab the system wide podman-restart.service and drop it into your $HOME/.config/systemd folder:
cp /lib/systemd/system/podman-restart.service $HOME/.config/systemd/user/
Next, enable the service:
systemctl --user enable podman-restart.service
You also need to enable linger because it’s a rootless systemd service:
loginctl enable-linger $UID
Finally, ensure the podman.socket is active and your DOCKER_HOST environment variable is pointing to it:
# Start the socket for the current user
systemctl --user enable --now podman.socket
# Point Docker Compose to Podman's socket
export DOCKER_HOST="unix://$XDG_RUNTIME_DIR/podman/podman.sock"
And that’s it. Now you can use docker-compose (or podman-compose, though I don’t really recommend it) just like you would with Docker.
Refs #
Don’t shine so others can see you. Shine so that through you others can see Him.
– C.S. Lewis