I have an application, which I would like to run as systemd user services.
This application can interact with Docker containers, which works when I run the application like /usr/bin/app
from User u
.
But when I load the application as a user service, systemctl enable --now --user app.service
, I get the following error:
time="2023-06-19T14:43:15+02:00" level=error msg="Cannot get containers: could not get containers from Docker (Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get \"http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/json?all=1&limit=0\": dial unix /var/run/docker.sock: connect: permission denied)"
The systemd service is defined as
[Unit]
Description=App description
After=network.target
[Service]
ExecStart=/usr/bin/app
Restart=always
[Install]
WantedBy=default.target
Should the service behave like "just" running the application as a binary?
The user is already in the Docker group.
I have looked at:
But neither solves my problem.
I found out what was wrong. Even though the Docker host was set in the environment for the user. It was not available to the the service.
Therefore in the code of the service I set an environment variable that correctly configured the docker host. It is not pretty but it works