【发布时间】:2018-04-26 03:43:34
【问题描述】:
例如在localhost 上,我们只需引用localhost:port 来连接到在本地机器上的端口port 上运行的进程。有没有办法引用容器正在运行的网络,所以我们不必担心和硬编码特定容器/服务的 ip 是什么。例如,如果我们想连接到 postgresql 数据库,我们只需写 bridge1:5432。
编辑:@fly2matrix 建议使用命名容器解决方案,但它不起作用,docker network inspect bridge 返回
...
"Containers": {
"2375b29321dc4a5947f8b63b46fe1c955f43fb1fbca64bb2adce3503380dda37": {
"Name": "somepostgres",
"EndpointID": "398ec0e792b836ceb5dd5d2e448e813047f9157ad90283b448e40eaf3f4f5b66",
"MacAddress": "02:42:ac:11:00:03",
"IPv4Address": "172.17.0.3/16",
"IPv6Address": ""
},
"a72fbb333e2d8cd3b7b78205795456fadc44678348ccedc58a78510cd273505b": {
"Name": "pizz",
"EndpointID": "2e7aa30844a632f4d42e3d0cfa16003dfd1d86aef85e63d16c83b3a71601e134",
"MacAddress": "02:42:ac:11:00:02",
"IPv4Address": "172.17.0.2/16",
"IPv6Address": ""
}
},
我的容器在同一条船上,但如果我尝试从 pizz 容器连接到 somepostgres:5432,它只会显示“未知主机”。
【问题讨论】:
标签: docker networking fedora