在 Vagrant 下运行 CoreOS 的 Ubuntu 主机上,我有一个在端口 80 上运行 nginx 的 docker 容器。
docker run -v /home/core/share:/var/www:rw -p 80:80 -d nginx-example
"NetworkSettings": {
"Bridge": "docker0",
"Gateway": "10.1.42.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "10.1.0.12",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"LinkLocalIPv6Address": "fe80::42:aff:fe1:c",
"LinkLocalIPv6PrefixLen": 64,
"MacAddress": "02:42:0a:01:00:0c",
"PortMapping": null,
"Ports": {
"80/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "80"
}
]
}
},
ifconfig
来自核心:docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.1.42.1 netmask 255.255.0.0 broadcast 0.0.0.0
inet6 fe80::d81e:ceff:fee7:f6ef prefixlen 64 scopeid 0x20<link>
ether b2:d5:75:c1:88:94 txqueuelen 0 (Ethernet)
RX packets 46089 bytes 1871717 (1.7 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 91776 bytes 81647104 (77.8 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.2.15 netmask 255.255.255.0 broadcast 10.0.2.255
inet6 fe80::a00:27ff:fe0d:b324 prefixlen 64 scopeid 0x20<link>
ether 08:00:27:0d:b3:24 txqueuelen 1000 (Ethernet)
RX packets 332980 bytes 285337617 (272.1 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 172343 bytes 9961980 (9.5 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.8.101 netmask 255.255.255.0 broadcast 172.17.8.255
inet6 fe80::a00:27ff:fed1:9f09 prefixlen 64 scopeid 0x20<link>
ether 08:00:27:d1:9f:09 txqueuelen 1000 (Ethernet)
RX packets 114 bytes 34912 (34.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 93 bytes 10008 (9.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
最佳答案
默认情况下,Docker 为容器管理自己的内部网络。
一个简单的解决方案可能是通过 Vagrant 设置映射端口,并让您的其他机器连接到主机(并传递给 Docker guest )。
或者,Docker 确实支持 --net=host
选项,允许容器直接通过主机的接口(interface)连接到外部世界,但是你失去了事物的“docker-ness”。
如果您想构建更强大的解决方案,您可以 set up the Docker networking manually并实现某种NAT网关到主机的局域网。
https://stackoverflow.com/questions/30264875/