Restart docker container


I am trying to restart a docker container (3rd party, not OH) from the OH (via Google Assistant switch and executeCommandLine).
I looked here:

and modified my sudoers as:

openhab ALL=(ALL) NOPASSWD: /usr/bin/docker
openhab ALL=(ALL) NOPASSWD: /var/run/docker.sock

I am running OH3 on rPi4, 8GB RAM
When I try to execute the restart container command from the terminal as openhab user I get this:

openhab@openHABianDevice:/home/openhabian$ docker container restart openhabian_inkbird_1
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/openhabian_inkbird_1/restart: dial unix /var/run/docker.sock: connect: permission denied

What should be entered in the sudoers file?


You still have to type in sudo
You just ran it as openhab

sudo -u openhab docker container restart openhabian_inkbird_1

Ideally you really want to set up the permissions so that any member of the docker group can issue commands to Docker. Then all you have to do is add the docker group to the openhab user and openHAB will have permission. No sudo required.

NOTE: I think /var/run/docker.sock is just a socket, not an executabe. Adding that to sudoers isn’t going to do anything for you.

1 Like

Thanks both, using sudo in the command solves the problem. I didn’t try editing the other permissions since I got what I needed.
And indeed removing var/run/docker.sock doesn’t make any difference for my application