解决Ubuntu18.04启动Docker"Got permission denied while trying to connect to the Docker daemon socket"问题

目录docker

1 问题描述json

2 缘由分析socket

3 解决方法unix

4 检查是否更新成功code


1 问题描述

在终端执行"docker version"命令,出现以下报错:blog

”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“进程

2 缘由分析

来自docker mannual:ip

Manage Docker as a non-root userit

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.io

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.

 docker进程使用Unix Socket而不是TCP端口。而默认状况下,Unix socket属于root用户,所以须要root权限才能访问。

3 解决方法

sudo groupadd docker #添加docker用户组
sudo gpasswd -a $XXX docker #检测当前用户是否已经在docker用户组中,其中XXX为用户名,例如个人,liangll
sudo gpasswd -a $USER docker #将当前用户添加至docker用户组
newgrp docker #更新docker用户组

4 检查是否更新成功

再次执行"docker version"命令,发现再也不出现"Got permission denied"权限报错