启动docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/r

启动docker提示:

docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.40/containers/create?name=hjenkins: dial unix /var/run/docker.sock: connect: permission denied.

启动docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/r

 

 

权限问题:

1.查看所有用户组与用户

vim /etc/group

/etc/group 的内容包括用户组(Group)、用户组口令、GID及该用户组所包含的用户(User),每个用户组一条记录;格式如下:

group_name:passwd:GID:user_list

在/etc/group 中的每条记录分四个字段:

第一字段:用户组名称;

第二字段:用户组密码;

第三字段:GID

第四字段:用户列表,每个用户之间用,号分割;本字段可以为空;如果字段为空表示用户组为GID的用户名;

2.把jenkins用户加入到dockerroot用户组

gpasswd -a jenkins dockerroot #将登陆用户加入到docker用户组中

newgrp dockerroot #更新用户组

3.重启jenkins

hello world!

普通用户使用docker的方法
添加用户组,将用户添加到组,重启docker即可

[root@localhost ~]# groupadd docker
[root@localhost ~]# groups
root
[root@localhost ~]# usermod -a -G docker wade 
[root@localhost ~]# grep docker /etc/group
dockerroot:x:994:
docker:x:1001:wade 
[root@localhost ~]# service docker restart
Redirecting to /bin/systemctl restart docker.service
[root@localhost ~]# sudo wade 
[wade @localhost ~]$ docker image ls

————————————————
版权声明:本文为CSDN博主「wade3015」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/wade3015/java/article/details/94588423

 

以下方法亲测可行:

1 问题描述
在终端执行"docker version"命令,出现如下报错:

”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:

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.

 docker进程使用Unix Socket而不是TCP端口。而默认情况下,Unix socket属于root用户,因此需要root权限才能访问。

3 解决方法
sudo groupadd docker #添加docker用户组
sudo gpasswd -a $XXX docker #检测当前用户是否已经在docker用户组中,其中XXX为用户名,例如我的,liangll。sudo gpasswd -a $uni docker
sudo gpasswd -a $USER docker #将当前用户添加至docker用户组
newgrp docker #更新docker用户组


4 检查是否更新成功
再次执行"docker version"命令,发现不再出现"Got permission denied"权限报错

启动docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/r

 

 

————————————————
版权声明:本文为CSDN博主「LL_Leung」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/liangllhahaha/java/article/details/92077065

上一篇:腾讯云服务器配置docker镜像源


下一篇:海思3520v300NDI协议移植