Running containers using systemd

Hi,

i’m trying to run LSIO containers using systemd under my user (using user lingering), but containers stops after a few seconds.

For example with Jackett, i have setup a unit file here: ~/.config/systemd/user/jackett.service

[Unit]
Description=Jackett

[Service]
TimeoutStartSec=10min
Restart=no
ExecStop=-/usr/bin/docker stop %N
ExecStartPre=-/usr/bin/docker rm %N
ExecStartPre=/usr/bin/docker pull linuxserver/jackett
ExecStartPre=/usr/bin/docker create --name %N -v %h/opt/appdata/jackett:/config -v /mnt/nas/media/Transit/blackhole/:/downloads -e PUID=%U -e PGID=1000 -v /etc/localtime:/etc/localtime:ro -p 9117:9117 linuxserver/jackett
ExecStart=/usr/bin/docker start %N

[Install]
WantedBy=multi-user.target

When i run the service with systemd, the conainer is created, runs for a few seconds, and exit.
docker logs on the container yields the following:

[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] 10-adduser: executing... 
[cont-finish.d] executing container finish scripts...
[cont-finish.d] done.
[s6-finish] syncing disks.
[s6-finish] sending all processes the TERM signal.
[s6-finish] sending all processes the KILL signal and exiting.

Does anyone know why this is happening?
Is there maybe a guide on how to setup LSIO containers as systemd services?

I would like the containers to run at startup and restart on failure, so systemd seemed like a good option, but maybe there is another way (on Ubuntu) ?

Thanks !

Our libreelec docker addons are managed via systemd.

Although I don’t see anything wrong with your service file, you should check systemd logs via journalctl -xe

I would really recommend using docker-compose instead of systemd, though.

With compose is it possible to start containers at boot?
I think auto restart policies are built-in.

Also, how would you handle scheduled restart of containers every week to ensure latest version from lsio is used?

In your compose yml, add the restart directive and you can set it to unless-stopped and they’ll start on boot.

With compose, updating containers is easy. First, you do a docker-compose pull to update images and then a docker-compose up -d, which will recreate containers as necessary (only the ones with an image update) and will start them. Afterwards, you can do a docker image prune -f to remove any old images.

I have a script that has the three commands above. I manually run it when I want to update. But you can put it in cron if you want to automate.

That sounds like an interesting approach, i didn’t know compose would restart containers upon reboot!

I will give it a try, thanks for the hints.