Introduction
When installing docker on Centos7 via yum, normal users can not directly use docker commands. Only root can do that.
Using the default configuration, a standard user trying to use docker command will see the following error message :
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
If you are tired of using sudo
command, you can allow a normal user to use docker commands using the following steps.
Allow a normal user to run docker
Add user to the docker group
The docker installation should have created a dockerroot
group. The first step is to declare you user as member of that group
usermod -aG dockerroot <username>
That is not all, the user will still not be able to connect to the daemon as the corresponding socket (/var/run/docker.sock
) belongs to root.
To change that and make it permanent (a simple chmod
will not do), tell the docker daemon to run as group dockerroot
via the docker configuration.
Change ownership of the docker daemon socket
Edit (or create) /etc/docker/daemon.json
{ "live-restore": true, "group": "dockerroot" }
Note for Docker 1.12 : when updating your CentOS distribution, the rpm might have deleted your /etc/docker/daemon.json
file.
If this is the case, simply restore /etc/docker/daemon.json
from /etc/docker/daemon.json.rpmsave
.
And then restart the docker daemon
systemctl restart docker
Make sure everything works
the file /var/run/docker.sock
should now belong to root:dockerroot
.
After re-login with your normal user, you should be able to run docker
27/02/2017 at 07:27
Thanks,It seems that Docker use the default group “docker” for a standard user running it without sudo.
https://docs.docker.com/engine/installation/linux/linux-postinstall/
I don’t know why Redhat create the group “dockerroot” since they didn’t add that group in the daemon.json file.
LikeLike
19/12/2017 at 09:25
Yes this would be for the docker version 1.12 found in the default centos repositories. For using the Community Edition, the docker user is used and not dockerroot.
LikeLiked by 2 people
02/01/2018 at 06:00
thanks!
LikeLiked by 1 person
03/01/2019 at 16:00
Thnaks a lot for the tips
LikeLike