docker:无法连接到unix上的Docker守护程序:///var/run/docker. sock,Docker守护程序是否正在运行?

bz4sfanl  于 2023-01-20  发布在  Docker
关注(0)|答案(2)|浏览(218)

我通过Visual Studio Code(VScode,版本1.66)远程连接到学校服务器(Ubuntu 20.04.2 LTS)执行一些任务,今天我跟随docker.com(https://docs.docker.com/engine/install/ubuntu/)在Ubuntu上安装了Docker引擎。
当我执行sudo docker run hello-world以通过在所有步骤之后运行hello-world映像来验证Docker Engine是否正确安装时,它显示如下错误:

docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'.

之后,我检查docker version,它显示

Client: Docker Engine - Community
 Version: 20.10.14
 API version: 1.41
 Go version: go1.16.15
 Git commit: a224086
 Built: Thu Mar 24 01:48:02 2022
 OS/Arch: linux/amd64
 Context: default
 Experimental: true
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

然后看一下sudo docker info,它显示

Client:
 Context: default
 Debug Mode: false
 Plugins:
  app: Docker App (Docker Inc., v0.9.1-beta3)
  buildx: Docker Buildx (Docker Inc., v0.8.1-docker)
  scan: Docker Scan (Docker Inc., v0.17.0)

Server:
ERROR: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
errors pretty printing info

在我按照这个教程卸载和重新安装docker后,它仍然显示这样的错误,我想我需要按照docker的服务器端,但我不知道如何做?
这是历史:

root@yp:~# sudo apt-get remove docker docker-engine docker.io containerd runc
...
root@yp:~# sudo apt-get update
...
root@yp:~# sudo apt-get install \
>     ca-certificates \
>     curl \
>     gnupg \
>     lsb-release
...
root@yp:~# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
...
root@yp:~# echo \
>   "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
>   $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
...
root@yp:~# sudo apt-get update
...
root@yp:~# sudo apt-get install docker-ce docker-ce-cli containerd.io
...
root@yp:~# sudo docker run hello-world
docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'.
7cwmlq89

7cwmlq891#

您应该首先在systemctl中启动并启用Docker

systemctl start docker
 systemctl enable docker
dgtucam1

dgtucam12#

刚刚解决了与此类似的问题

您应该做的第一件事是在您的PC上安装Docker Desktop,您可以从此处获得https://docs.docker.com/desktop/windows/wsl/
您还应该启用wsl 2,只需浏览上面链接中的文档就足够了。
确保进入设置〉资源〉WSL集成并启用Ubuntu-20.04或您正在使用的任何其他发行版。
同时确保选中设置〉常规〉使用基于WSL 2的引擎...复选框

相关问题