docker runtime common errors

docker runtime common errors

(1) Cannot connect to the Docker daemon at unix:///var/run/docker.sock.

[root@localhost geo]# docker version
Client: Docker Engine - Community
 Version:           19.03.8
 API version:       1.40
 Go version:        go1.12.17
 Git commit:        afacb8b
 Built:             Wed Mar 11 01:27:04 2020
 OS/Arch:           linux/amd64
 Experimental:      false
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docke                                                              r daemon running?

solve

systemctl daemon-reload

systemctl restart docker.service

# 或者
service docker restart

(2) Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock

[geo@localhost ~]$ docker version
Client: Docker Engine - Community
 Version:           19.03.8
 API version:       1.40
 Go version:        go1.12.17
 Git commit:        afacb8b
 Built:             Wed Mar 11 01:27:04 2020
 OS/Arch:           linux/amd64
 Experimental:      false
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.40/version: dial unix /var/run/docker.sock: connect: permission denied

the reason

Excerpt from a talk on the docker mannual

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.

Probably mean is: docker process instead of using Unix Socket TCP port. And by default, Unix socket belongs to the root user, you need root privileges to access.

Workaround 1

Use sudo to obtain administrator privileges, run the command docker

Solution 2

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

sudo groupadd docker     #添加docker用户组
sudo gpasswd -a $USER docker     #将登陆用户加入到docker用户组中
newgrp docker     #更新用户组
docker ps    #测试docker命令是否可以使用sudo正常使用

Guess you like

Origin www.cnblogs.com/geoffreygao/p/12608987.html