在 unix:///var/run/docker.sock 尝试连接到 Docker 守护程序套接字时权限被拒绝



我们在尝试运行 docker 命令时收到此错误。 例如:

$ docker image ls
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.38/images/json: dial unix /var/run/docker.sock: connect: permission denied

因此,我们按照此处的步骤进行操作,但问题仍然存在。然后我们在建议的地方看到了这个问题

你必须重新启动 docker 守护进程,否则它不会让成员 用于控制 Docker 守护程序的 docker 组

但在重新启动服务时遇到问题

$ sudo service docker restart
Failed to restart docker.service: Unit docker.service not found.

我们正在使用

$ docker -v
Docker version 18.06.1-ce, build e68fc7a

$ uname -a
Linux jnj 4.15.0-1036-azure #38-Ubuntu SMP Fri Dec 7 02:47:47 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

Docker组已成功创建,我们是其中的成员

$ grep docker /etc/group
docker:x:1001:siddjain

我们也确实注销并重新登录。 我们能够使用 sudo 运行 docker 命令。也

$ sudo snap services
Service         Startup  Current  Notes
docker.dockerd  enabled  active   -

谁能帮助我们?

解决方案是使用 snap 重新启动 docker 守护进程(因为这就是我们安装 docker 的方式)

siddjain@jnj:~$ sudo snap stop docker
Stopped.
siddjain@jnj:~$ snap start docker
error: access denied (try with sudo)
siddjain@jnj:~$ sudo snap start docker
Started.

之后,我们可以运行 docker 命令而无需sudo

siddjain@jnj:~$ docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/
For more examples and ideas, visit:
 https://docs.docker.com/get-started/
siddjain@jnj:~$ 

我们的喜悦是短暂的,因为当我们尝试运行另一个容器时,我们立即遇到了另一个错误。

mkdir /var/lib/docker: read-only file system

为了修复它,我们不得不再次卸载并重新安装 docker - 这次来自官方文档,如此处所述

相关内容

最新更新