在 Hyper-V 上手动设置默认 docker-machine

Make default docker-machine manually on Hyper-V

我有时会在 Docker 上遇到 Windows 的这个错误。

我用谷歌搜索了一下,找到了原因。

结果是因为没有docker-机器默认

$docker ps
error during connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.38/containers/json: open //./pipe/docker_engine: The system cannot find the file specified. In the default daemon configuration on Windows, the docker client must be run elevated to connect. This error may also indicate that the docker daemon is not running.

我的 OS 是 Windows 10 所以使用了 Hyper-V。

所以我这样尝试,

docker-machine create --driver hyperv default

但是它显示这样的错误。

Error with pre-create check: "no External vswitch found. A valid vswitch must be available for this command to run. Check https://docs.docker.com/machine/drivers/hyper-v/"

我真的经常被这个错误困扰。

我该如何解决?


我用 hyperv-virtual-switch 选项表示 DockerNAT

docker-machine create --driver hyperv --hyperv-virtual-switch DockerNAT default

看起来有进步。

Running pre-create checks...
(default) Image cache directory does not exist, creating it at C:\Users\whitebear\.docker\machine\cache...
(default) No default Boot2Docker ISO found locally, downloading the latest release...
(default) Latest release for github.com/boot2docker/boot2docker is v18.06.0-ce
(default) Downloading C:\Users\whitebear\.docker\machine\cache\boot2docker.iso from https://github.com/boot2docker/boot2docker/releases/download/v18.06.0-ce/boot2docker.iso...
(default) 0%....10%....20%....30%....40%....50%....60%....70%....80%....90%....100%
Creating machine...
(default) Copying C:\Users\whitebear\.docker\machine\cache\boot2docker.iso to C:\Users\whitebear\.docker\machine\machines\default\boot2docker.iso...
(default) Creating SSH key...
(default) Creating VM...
(default) Using switch "DockerNAT"
(default) Creating VHD
(default) Starting VM...
(default) Waiting for host to start...
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Detecting the provisioner...
Provisioning with boot2docker...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
Checking connection to Docker...
Docker is up and running!

终于,docker-机器工作了。

PS C:\Windows\system32> docker-machine ls
NAME      ACTIVE   DRIVER   STATE     URL                        SWARM   DOCKER        ERRORS
default   -        hyperv   Running   tcp://192.168.1.118:2376           v18.06.0-ce

但是 docker ps 还没有生效。

PS C:\Windows\system32> docker ps
error during connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.38/containers/json: open //./pipe/docker_engine: The system cannot find the file specified. In the default daemon configuration on Windows, the docker client must be run elevated to connect. This error may also indicate that the docker daemon is not running.

您可以手动创建外部 vswitch,然后在 docker-machine create ... 期间 select 创建它。有关类似问题,请参阅 。

https://rominirani.com/docker-machine-windows-10-hyper-v-troubleshooting-tips-367c1ea73c24 上的博客提供了有关 docker-machine 的其他可能问题的更多详细信息。