为什么启动Docker容器会更改主机的默认路由?
我用下面的路由表configuration我的主机:
user@host:~ $ netstat -rn Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface {VPN SERVER IP} 192.168.2.1 255.255.255.255 UGH 0 0 0 wlan0 172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0 192.168.2.0 0.0.0.0 255.255.255.0 U 0 0 0 wlan0
所以,没有连接到VPN,我没有连接到互联网:
user@host:~ $ ping google.com connect: Network is unreachable
一旦我启动我的docker容器主机的路由表变成:
user@host:~ $ netstat -rn Destination Gateway Genmask Flags MSS Window irtt Iface 0.0.0.0 192.168.2.1 0.0.0.0 UG 0 0 0 wlan0 {VPN SERVER IP} 192.168.2.1 255.255.255.255 UGH 0 0 0 wlan0 169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0 169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 vethcbeee28 172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0 192.168.2.0 0.0.0.0 255.255.255.0 U 0 0 0 wlan0
而且我又连接到了互联网:
user@host:~ $ ping google.com PING google.com (216.58.212.238) 56(84) bytes of data.
基本上我的主机不能连接到互联网,而不连接到VPN。 但是,启动容器将默认路由再次设置到我的网关。
有人知道这里发生了什么吗? 而且,如何避免呢?
到目前为止,我在这里find了一个解决方法,我想避免这个问题。
编辑:
我只是发现,这甚至发生,甚至从docker文件build立一个图像!
您可以在/etc/dhcpd.conf
文件中指定nogateway
选项。
# Avoid to set the default routes. nogateway
- Docker和Vagrant连接
- 无法安装postcrip php模块到docker
- 如何监听docker事件并在新事件发出时运行命令?
- 我如何禁用docker集装箱的互联网访问
- System.InvalidOperationException:“path基础只能使用IApplicationBuilder.UsePathBase()configuration。
- Dockerized Angular 4和Django编译成功,但localhost:4200不能正常工作
- 文件权限和所有权Elastic Beanstalk多容器Docker环境aws
- 如何在“Docker for Windows”中启用docker remote API
- 我无法从Dockered Django Web应用程序login。 哪里不对?