Docker daemon socket权限不足

一、概述

普通用户执行命令:docker ps报错,具体信息如下:

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.38/containers/create: dial unix /var/run/docker.sock: connect: permission denied.

 

出现上面问题是因为:

Manage Docker as a non-root user
即:管理Docker的不是root用户

 

原文表述:

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权限才能访问。

 

二、解决方案

方案一:使用sudo获取管理员权限,运行docker命令
方案二:添加docker group组,将用户添加进去

环境说明

操作系统:centos 7.6

docker版本:19.03.5

 

由于采用的是jumpserver方式登录,开发人员使用的是develop账号。

docker安装之后,默认会创建组docker,因此不需要再创建了。

 

执行命令

使用root账号登录目标服务器

#将登陆用户develop加入到docker用户组中
gpasswd -a develop docker
#更新用户组
newgrp docker

 

切换到develop用户进行测试

su develop
docker ps

输出正常,则表示成功了。

 

 

本文参考链接:

https://www.jianshu.com/p/a0cf03605c42

 

posted @   肖祥  阅读(1371)  评论(0编辑  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
点击右上角即可分享
微信分享提示