我创建了一个用户定义的网络(桥接模式)hb1 并添加了 2 个容器。但是,我无法从网络上的外部主机连接到它们。
pi@raspberrypi:~ $ docker network inspect hb1
[
{
"Name": "hb1",
"Id": "278a4ba8bb7a4a34b25b5f5fde9a965a807ff896d5e57c2b1d7d39af60d0a046",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": {},
"Config": [
{
"Subnet": "192.168.1.32/27",
"Gateway": "192.168.1.33"
}
]
},
"Internal": false,
"Containers": {
"7dc7be3ae45813450bb7f75a6e2c7b4d93e59aa147aa7d393061748b8201381a": {
"Name": "modest_bohr",
"EndpointID": "eda20bbb52319b10911f3da6f6afadbd2167298d5a9cfd5c91f933f4b6d5fe86",
"MacAddress": "02:42:c0:a8:01:22",
"IPv4Address": "192.168.1.34/27",
"IPv6Address": ""
},
"f12fbc30bcf5e37737bfe8c7868dcd40e6c632bb3672f5641ffd6960ede4f777": {
"Name": "infallible_torvalds",
"EndpointID": "92d0ecfad597485c25ad309d48c3c77b9368f25ebbd851b1168f59a795c497f2",
"MacAddress": "02:42:c0:a8:01:23",
"IPv4Address": "192.168.1.35/27",
"IPv6Address": ""
}
},
"Options": {},
"Labels": {}
}
]
当我从我的 docker 主机 ping 时,它按预期工作。
user@myhost: ~$ ping -c 1 192.168.1.34
PING 192.168.1.34 (192.168.1.34) 56(84) bytes of data.
64 bytes from 192.168.1.34: icmp_seq=1 ttl=64 time=0.474 ms
--- 192.168.1.34 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.474/0.474/0.474/0.000 ms
但是,无法从远程主机访问容器。
user@remotehost: ~$ ping -c 1 192.168.1.34
PING 192.168.1.34 (192.168.1.34) 56(84) bytes of data.
From 192.168.1.100 icmp_seq=1 Destination Host Unreachable
--- 192.168.1.34 ping statistics ---
1 packets transmitted, 0 received, +1 errors, 100% packet loss, time 0ms
我应该如何配置 docker 用户定义的网络或我的本地网络,以便我可以在单独的 IP 地址上访问容器?