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

Advertisements