Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock
Docker to The socket at connect while unix
2023-09-11 14:22:17 时间
安装完docker后,执行docker相关命令,出现:
”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“
原因
摘自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权限才能访问。
解决方法1
使用sudo获取管理员权限,运行docker命令
解决方法2
docker守护进程启动的时候,会默认赋予名字为docker的用户组读写Unix socket的权限,因此只要创建docker用户组,并将当前用户加入到docker用户组中,那么当前用户就有权限访问Unix socket了,进而也就可以执行docker相关命令
sudo groupadd docker #添加docker用户组
sudo gpasswd -a $USER docker #将登陆用户加入到docker用户组中
newgrp docker #更新用户组
docker ps #测试docker命令是否可以使用sudo正常使用
相关文章
- 记录一次在生成数据库服务器上出现The timeout period elapsed prior to completion of the operation or the server is not responding.和Exception has been thrown by the target of an invocation的解决办法
- 【Docker】docker安装Jenkins
- 【Docker】iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 8480 -j DNAT --to-destination 172.17.0.2:80 ! -i docker0: iptables: No chain/target/match by that name
- SQLBackupAndFTP The server principal "NT AUTHORITYSYSTEM" is not able to access the database "xxxx"
- centos ERROR: Couldn't connect to Docker daemon at http+docker://localhost - is it running?
- Docker - docker in docker(dind)
- [Docker] Push container to Docker hub
- docker的安装和配置
- [Docker] Converting from Docker Compose to Kubernetes
- 解决docker push镜像到私有仓库时的报错【http: server gave HTTP response to HTTPS client】
- 成功解决To fix this you could try to: 1. loosen the range of package versions you‘ve specified
- Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
- 【docker】解决 Failed with result ‘exit-code‘和Start request repeated too quickly和Failed to start Docker
- Docker“Got permission denied while trying to connect to the Docker daemon socket“问题
- Docker使用阿里云docker镜像加速
- 76.第十七章 企业级容器技术docker -- Docker 镜像制作和管理(四)
- 问题解决:The connection to the server xxxxx:6443 was refused - did you specify the right host or port?
- 【云原生之Docker实战】使用docker部署短链接服务YOURLS
- 【云原生之Docker实战】使用docker部署kooteam在线团队协作工具
- 【云原生之Docker实战】使用docker部署koel家庭个人音乐服务器
- 【Docker】之docker-compose的介绍与命令的使用
- Docker重学系列之docker可视化工具