Solve non-root user does not have permission to run the command issue docker

Problem Description:

”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.26/images/json: dial unix
/var/run/docker.sock: connect: permission denied“

The reason (taken from the docker's manual):

Manage Docker as a non-root user

The docker daemon binds to a Unix socket instead of a TCP port. By
default that Unix socket is owned by the user root and other users can
only access it using sudo. The docker daemon always runs as the root
user.

If you don’t want to use sudo when you use the docker command, create
a Unix group called docker and add users to it. When the docker daemon
starts, it makes the ownership of the Unix socket read/writable by the
docker group.

The obvious answer is to not root user, or create a user group named docker and you need to use the non-root user docker to add to the group, if it does not do, read on.

Method 1:
Use sudo to obtain administrator privileges, run docker command, this method will have many limitations when executing commands through scripts docker

Method 2:
docker daemon is started when the default permissions granted to read and write the name of the user group docker Unix socket, so long as the docker to create user groups, and the current user to the docker user group, then the current user have permission access Unix socket, and then it can execute commands related to docker

sudo groupadd docker     #添加docker用户组
sudo gpasswd -a $USER docker     #将登陆用户加入到docker用户组中
newgrp docker     #更新用户组
Published 21 original articles · won praise 5 · views 10000 +

Guess you like

Origin blog.csdn.net/icodestechnology/article/details/97170540