ubuntu docker报错
以下問(wèn)題及解決方法都在Ubuntu16.04下,其他環(huán)境類似
問(wèn)題描述
安裝完docker后,執(zhí)行docker相關(guān)命令,出現(xiàn)
”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進(jìn)程使用Unix Socket而不是TCP端口。而默認(rèn)情況下,Unix socket屬于root用戶,需要root權(quán)限才能訪問(wèn)。
解決方法1
使用sudo獲取管理員權(quán)限,運(yùn)行docker命令
解決方法2
docker守護(hù)進(jìn)程啟動(dòng)的時(shí)候,會(huì)默認(rèn)賦予名字為docker的用戶組讀寫Unix socket的權(quán)限,因此只要?jiǎng)?chuàng)建docker用戶組,并將當(dāng)前用戶加入到docker用戶組中,那么當(dāng)前用戶就有權(quán)限訪問(wèn)Unix socket了,進(jìn)而也就可以執(zhí)行docker相關(guān)命令
sudo groupadd docker #添加docker用戶組 sudo gpasswd -a $USER docker #將登陸用戶加入到docker用戶組中 newgrp docker #更新用戶組 docker ps #測(cè)試docker命令是否可以使用sudo正常使用轉(zhuǎn)載于:https://www.cnblogs.com/plusUltra/p/11206943.html
總結(jié)
以上是生活随笔為你收集整理的ubuntu docker报错的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 【JLOI2013】地形生成
- 下一篇: Ubuntu 14 查看 docker中