Docker启动时提示Get Permission Denied while trying to connect解决方法
生活随笔
收集整理的這篇文章主要介紹了
Docker启动时提示Get Permission Denied while trying to connect解决方法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
環境描述
vmware15虛擬機安裝centos7.4 64位系統,docker版本19.03.2
問題描述
安裝完docker后,執行docker相關命令
docker run ubuntu:15.10 /bin/echo "Hello world"
出現如下提示:
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: 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命令
#如下命令可以正常執行
sudo docker run ubuntu:15.10 /bin/echo "Hello world"
解決方法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正常使用
總結
以上是生活随笔為你收集整理的Docker启动时提示Get Permission Denied while trying to connect解决方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: centos7右键添加新建空白文件或文档
- 下一篇: SQL Server(MSSQLSERV