1
csuzhangxc 2020-06-20 10:27:31 +08:00 via Android
不通过环境变量传进去?
|
2
ypcs03 2020-06-20 10:30:52 +08:00
aws ec2 可以通过 IMDS, 其他的 cloud provider 应该也有类似的吧。通用的貌似不太容易,还跟容器的 config 有关比如--net=host.
|
3
moonsn 2020-06-20 10:34:02 +08:00 via Android
I WANT TO CONNECT FROM A CONTAINER TO A SERVICE ON THE HOST
The host has a changing IP address (or none if you have no network access). From 18.03 onwards our recommendation is to connect to the special DNS name host.docker.internal, which resolves to the internal IP address used by the host. This is for development purpose and will not work in a production environment outside of Docker Desktop for Mac. The gateway is also reachable as gateway.docker.internal. |
4
moonsn 2020-06-20 10:35:02 +08:00 via Android
macos 的话,如上。
|
5
Latin 2020-06-20 10:37:22 +08:00
挂宿主机 /proc 到容器 /host/proc,
运行容器加 --privileged nsenter --net=/host/proc/1/ns/net ifconfig 网卡名 |
6
cheng6563 2020-06-20 11:38:40 +08:00 via Android
没办法,脚本里先获得 IP 再启动容器吧
|
7
0312birdzhang 2020-06-20 12:26:59 +08:00 via iPhone
1 楼加一,其他方法不推荐
|
8
Ezez OP |
9
Jirajine 2020-06-20 14:50:27 +08:00 via Android
|
11
Ezez OP 我的目的是要把这个插件能做成一个通用的插件,查了一圈,感觉不太可能,毕竟不同项目,配置或者是启动方式都不一样
|
12
HTSdTt3WygdgQQGe 2020-06-20 15:47:32 +08:00 via Android
curl ip.sb
|
13
Smilencer 2020-06-20 15:58:09 +08:00
我的做法是容器启动时,增加 host,自动将宿主机 docker 网关映射到 dockerhost
``` docker run --add-host=dockerhost:`docker network inspect --format='{{range .IPAM.Config}}{{.Gateway}}{{end}}' bridge` ``` |
14
holosola 2020-06-20 16:16:58 +08:00 via Android
试试用 host.docker.internal
|
16
julyclyde 2020-06-28 18:17:02 +08:00
需求有错
跨机器的通信,命名服务也应该是外部的而不是上下级传递的 |