Docker Windows 和 WSL1 一起工作

Docker for Windows and WSL1 to Work together

Ubuntu WSL with docker could not be found

完全相同的问题
$ docker

The command 'docker' could not be found in this WSL 1 distro.
We recommend to convert this distro to WSL 2 and activate
the WSL integration in Docker Desktop settings.

See https://docs.docker.com/docker-for-windows/wsl/ for details.

但我的要求不同 -- 我想

即,我将 Windows 的 WSL1 和 Docker 并排安装。这是我的当前信息:

C:> ver
Microsoft Windows [Version 10.0.18363.1379]

C:> wsl -l -v
  NAME      STATE           VERSION
* Debian    Running         1

我没有在“资源 -> WSL 集成”中看到集成,并且我没有在 Docker 桌面设置中启用 WSL2 后端。

只是我遇到了上述问题——我的 docker 可以在任何地方工作,在 CMD、Powershell、git-bash 等中,只是不在我的 WSL 中。

我找到的所有解决方案都是为 Windows within WSL1 或 WSL2 安装 Docker,但我想保持一切原样 -- WSL和 Docker for Windows 安装彼此平行.

有什么解决办法吗?

The command 'docker' could not be found in this WSL 1 distro.
We recommend to convert this distro to WSL 2 and activate
the WSL integration in Docker Desktop settings.

这意味着在 WSL2 中,它有一个真正的 linux 内核,需要安装 docker 守护进程,然后在 docker-desktop 中你可以设置 docker WSL2 中的守护程序。否则,docker 守护程序在 Hyper-V machine 中 运行ning。但是,如果你坚持 WSL1,就没有机会在 WSL 运行 docker-daemon,所以唯一的选择是 运行宁 docker daemonHyper-V machine .

虽然以上是事实,但我们还是有机会让你在WSL1bash中操作docker ps, docker pull等,就像你操作CMD, Powershell, git-bash一样,即allow Docker to accept requests from remote hosts.

对于您的情况,接下来的步骤可能是:

1.接下来在 docker desktop 设置中公开 docker 守护程序,然后单击 Apply & Restart:

2。在 WSL1 中安装独立的 docker 客户端:

$ wget https://download.docker.com/linux/static/stable/x86_64/docker-20.10.5.tgz
$ tar zxvf docker-20.10.5.tgz
$ cd docker

3。设置默认 docker 守护程序:

$ export DOCKER_HOST=tcp://localhost:2375

4。验证 docker 客户端命令:

$ ./docker info

只是 FTA,这是我在尝试自己解决时发现的快速 hacky 解决方法

C:\Program Files\Docker\Docker\resources\bin\docker 文件更改为

#!/usr/bin/env sh
#
# Copyright (c) Docker Inc.

binary=$(basename "[=10=]")
"$binary.exe" "$@"

然后docker现在可以在CMDPowershellgit-bash以及WSL1.

的任何地方工作

请注意,此 hacky 解决方法专门针对 OP 中描述的情况,可能不适用于其他任何情况。