Docker 在 Ubuntu 内 WSL

Docker on Ubuntu inside WSL

我想玩 hyperledger fabric,这需要 linux。 现在我想使用 Windows,我的想法是使用 WSL 安装 Ubuntu,然后在其中进行开发。 当我想使用 docker.

时出现问题

我按照 this tutorial 中的步骤一步步进行,但我 运行 遇到了一些问题。

filip@CSGN044D:~$ docker --version
Docker version 19.03.5, build 633a0ea838


filip@CSGN044D:~$ 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'.


filip@CSGN044D:~$ sudo service docker start
 * Starting Docker: docker

又一次...

filip@CSGN044D:~$ 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'.

这可能吗?

看起来您的 Docker CLI 仍在尝试连接到本地 Unix 套接字而不是本地主机。确保您的 DOCKER_HOST 环境变量设置为 tcp://localhost:2375

首先在您的 shell 中设置它

export DOCKER_HOST=tcp://localhost:2375

完整性检查

echo $DOCKER_HOST

现在尝试 运行 所有常规 Docker 命令。如果这些有效,请将其添加到您的 .bashrc

echo "export DOCKER_HOST=tcp://localhost:2375" >> ~/.bashrc
source ~/.bashrc

并不是说在教程中作者使用localhost:2375而不是tcp://localhost:2375。我认为您必须明确指定协议。此外,您的 shell 可能没有使用 bash_profile 作为配置文件(通常 Mac shell 使用它)因此请尝试将其添加到您的 bashrc