How to start podman containers at boot?

That’s basically it. I want to start my containers at boot. Anyone know how to do that?

I tried some solutions I found on the Internet, but I got some errors, like It is recommended to use Quadlets for running containers and pods under systemd.

1 Like

I use systemd services and think that is what that means.

podman generate systemd --new --name --files container-name

The above command will create a systemd service and you have to move that to the correct directory.

For rooted containers (what I think you’re going for), place it in one of the following directories:

/usr/share/containers/systemd/
/etc/containers/systemd/

If you are a rootless user, then the following directory works:
$HOME/.config/containers/systemd/

Afterwards, you can treat the container like a service and atart/stop as well as enable (autostart) and disable (don’t autostart).

The below link may provide more information.

1 Like

that’s the thing though. I already tried the command podman generate systemd --new --name --files portainer to do that, while following a guide. The problem is, I get the error

DEPRECATED command:
It is recommended to use Quadlets for running containers and pods under systemd.

I did some digging and found that quadlets are a new way to do what that command was doing with abstractions and such. Podman basically takes a yaml config file and make the services itself.

The yaml file includes all the config stuff you wanted to do with the container (like ports, environment variables and such).

To create a config file, there is a tool called podlet. You basically put podlet infront of the podman command and podlet should create an appropriate config file (though you need the --file flag also or it will just print the information).
Here is some documentation in the podlet Github repo:

Basically just do something like:

podlet podman run ...

However I should note that podlet still seems to be in development, just make sure to review the yaml to ensure it does what you want it to. To install it, you can get it from cargo (rust package manager), a podman container (you would have to run it within the container), or just get a binary from their GitHub releases.

Once you do have the .container yaml file, just put it in the location you were going to in the guide you saw. Then you reload the systemd daemon and manage the service.

Hope that helped! Note that I haven’t done any of this myself, I’ll leave some links I read from in case it helps.

2 Likes

A question though, can’t I just use docker instead of podman? I couldn’t find any guides on it, but it should be possible, right?

Docker isn’t on the bazzite image, it’s on aurora-dx and bluefin-dx though.

podlet is useful but it’s certainly not required for running podman containers using the new quadlet method. Its more of a migration utility.

I put off figuring out quadlets for too long. Then I found out that it’s actually way simpler then using the ‘podman generate systemd’ method. For example, here is (most of) my unit for running syncthing as my user:

[Unit]
Description=Syncthing container

[Container]
ContainerName=syncthing
Entrypoint=/bin/syncthing
Image=docker.io/syncthing/syncthing
Network=host
PublishPort=127.0.0.1:8384:8384
UserNS=keep-id

[Service]
Restart=always

[Install]
WantedBy=default.target

The [Container] section defines the container itself, the rest is for systemd. Files similar to that in .config/containers/systemd is all that is needed.

As for Docker, yes you could use that but I find podman integrates with the system in a much nicer way. Doesn’t need a group membership, doesn’t need a daemon running, run as the user by default.

So, the steps are:

  1. Install the container using podman;
  2. Generate thata file;
  3. Place it in .config/containers/systemd.

Doing that will ensure my containers will run on boot and keep runing?

This page https://mo8it.com/blog/quadlet/ mentioned above has a good summary, I think it’s what I used.

Take note of the part concerning:

loginctl enable-linger

You can create a systemd service to automatically start them for you. I got this from in the UCore image, but have not tested it in any other UBlue image. It will automatically start any container which has a restart: always policy.

Create a new service file at /var/home/USER/.config/systemd/user/podman-restart.service, with this contents:

[Unit]
Description=Podman Start All Containers With Restart Policy Set To Always
Documentation=man:podman-start(1)
StartLimitIntervalSec=0
Wants=network-online.target
After=network-online.target

[Service]
Type=oneshot
RemainAfterExit=true
Environment=LOGGING="--log-level=info"
ExecStart=/usr/bin/podman $LOGGING start --all --filter restart-policy=always
ExecStop=/bin/sh -c '/usr/bin/podman $LOGGING stop $(/usr/bin/podman container ls --filter restart-policy=always -q)'

[Install]
WantedBy=default.target

Then enable the new service:

systemctl --user enable podman-restart.service

That should hopefully be all you need :slight_smile:

Thank you, that worked. But I do have a question about it.

I noticed the container only starts when I switch to desktop, but it doesn’t start on boot (in game mode), so I have to switch to desktop if I want my services.

Is there a way for it to start with gamemode instead?