使用Hyper-V强制docker-machine到特定IP,网络无法访问

时间:2017-05-12 19:33:41

标签: hyper-v docker-machine

I have found a partial answer to this question,它已成功将机器设置为所需的IP地址。但是,使用Hyper-V驱动程序创建的docker-machine内部无法访问网络。

上面答案的TLDR是创建一个脚本/var/lib/boot2docker/bootsync.sh

sudo cat /var/run/udhcpc.eth0.pid | xargs sudo kill
sudo ifconfig eth0 192.168.XXX.YYY netmask 255.255.255.0 broadcast 192.168.XXX.255 up

制作完剧本后,我重启机器。

当我重新启动机器时,IP被设置为我想要的地址(预期)。我可以在地址远程访问,因此至少可以通过主机访问。但是当我测试连接时,没有连接到互联网(意外)。

Boot2Docker version 17.05.0-ce, build HEAD : 5ed2840 - Fri May  5 21:04:09 UTC 2017
Docker version 17.05.0-ce, build 89658be

docker@machine:~$ docker pull ubuntu
Using default tag: latest
Error response from daemon: Get https://registry-1.docker.io/v2/: dial tcp: lookup registry-1.docker.io on [::1]:53: read udp [::1]:48331->[::1]:53: read: connection refused

docker@machine:~$ ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8): 56 data bytes
ping: sendto: Network is unreachable

如果我删除脚本并重新启动,我将重新分配一个新的/随机IP地址(预期),远程进入该新IP地址,并且可以进行网络连接(预期):

docker@pm:~$ docker pull ubuntu
Using default tag: latest
latest: Pulling from library/ubuntu
aafe6b5e13de: Pull complete
0a2b43a72660: Pull complete
18bdd1e546d2: Pull complete
8198342c3e05: Pull complete
f56970a44fd4: Pull complete
Digest: sha256:f3a61450ae43896c4332bda5e78b453f4a93179045f20c8181043b26b5e79028
Status: Downloaded newer image for ubuntu:latest

docker@pm:~$ ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8): 56 data bytes
64 bytes from 8.8.8.8: seq=0 ttl=43 time=18.424 ms
64 bytes from 8.8.8.8: seq=1 ttl=43 time=27.638 ms

接受的答案有几个投票,但它看起来像是在VirtualBox上确认的工作。不确定Hyper-V会导致IP分配切断互联网访问。

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,我通过在bootsync.sh的末尾添加以下内容来解决它:

route add default gw <address>

没有到网关或互联网的默认路由,因此必须手动设置。