Java基础、中级、高级、架构面试资料

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

NDIS herman 1456浏览
公告:“业余草”微信公众号提供免费CSDN下载服务(只下Java资源),关注业余草微信公众号,添加作者微信:xttblog2,发送下载链接帮助你免费下载!
本博客日IP超过2000,PV 3000 左右,急需赞助商。
极客时间所有课程通过我的二维码购买后返现24元微信红包,请加博主新的微信号:xttblog2,之前的微信号好友位已满,备注:返现
受密码保护的文章请关注“业余草”公众号,回复关键字“0”获得密码
所有面试题(java、前端、数据库、springboot等)一网打尽,请关注文末小程序
视频教程免费领
腾讯云】1核2G5M轻量应用服务器50元首年,高性价比,助您轻松上云

今天同事在服务器上执行 docker ps 报错了,之前用的一直挺好的,今天突然用不了了。于是我连上服务器,一顿操作之后修复好了,本文记录一下修复过程!

完整错误信息如下:

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

www.xttblog.com

我网上搜索了很多答案,都不能解决问题,很多答案是从创建 docker 分组开始的。这种也可以解决,但是实际上过程有些麻烦,而且还可能不存在 docker 用户组的情况。

Got permission denied while trying to connect to the Docker daemon socket

后来我在 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 权限才能访问。说白了,就是权限不够。

然后,我看错误提示的是“/var/run/docker.sock: connect: permission denied”。

于是,我就抱着试试的心态,给 /var/run/docker.sock 添加了权限。

sudo chmod a+rw /var/run/docker.sock

然后重新登录其他非 root 用户后,完美解决。

当然下面这种也可以:

sudo groupadd docker     #添加 docker 用户组
sudo gpasswd -a xttblog docker     #将登陆用户 xttblog 加入到 docker 用户组中
newgrp docker  #更新用户组
docker ps #测试 docker 命令是否可以使用
sudo service docker restart # 重启 docker 服务

重启后,基本上就解决了。

cat /etc/group | grep docker # 查看/etc/group,确定是否存在docker组
docker:x:999:xttblog

业余草公众号

最后,欢迎关注我的个人微信公众号:业余草(yyucao)!可加作者微信号:xttblog2。备注:“1”,添加博主微信拉你进微信群。备注错误不会同意好友申请。再次感谢您的关注!后续有精彩内容会第一时间发给您!原创文章投稿请发送至532009913@qq.com邮箱。商务合作也可添加作者微信进行联系!

本文原文出处:业余草: » Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.