【发布时间】:2020-12-28 22:50:19
【问题描述】:
在 Ubuntu 20.04 上运行新的 Docker 20.10.1。此版本包括support for host.docker.internal in dockerd on Linux
root@docker04:~# docker --version
Docker version 20.10.1, build 831ebea
我在使用 SSL 证书的容器中运行一堆服务,我想使用 Telegraf 检查证书是否过期(以便稍后发送到 Grafana 仪表板)。
所有带有 Web 界面和 Telegraf 的服务都运行在同一个 Docker 主机上。所有服务都在自己的桥接网络中。我想在端口 9000 上连接 从 Telegraf 到 Portainer(见下文)。
----------VM running docker (10.10.1.32)----------
| |
| -------------------- |
| | Gitea | |
| | Ports: 3000:3000 | |
| | Network: gitea | |
| -------------------- |
| |
| ---------------------- |
| | Portainer | |
| | Ports: 9000:9000 |<--| |
| | Network: portainer | | |
| ---------------------- | |
| | |
| --------------------- | |
| | Telegraf | | |
| | Network: telegraf |-->- |
| | | |
| --------------------- |
| |
--------------------------------------------------
我认为有了对 host.docker.internal 的新支持,我将能够从一个容器连接到另一个容器,但这似乎不起作用。 Ping 可以,但我无法连接到端口 9000。
root@docker04:~# docker run -it --add-host host.docker.internal:host-gateway alpine /bin/sh
/ # ping host.docker.internal
PING host.docker.internal (172.17.0.1): 56 data bytes
64 bytes from 172.17.0.1: seq=0 ttl=64 time=0.102 ms
64 bytes from 172.17.0.1: seq=1 ttl=64 time=0.100 ms
^C
/ # telnet host.docker.internal 9000
telnet: can't connect to remote host (172.17.0.1): Operation timed out
最后一个 telnet 命令挂起并最终断开连接。我在这里错过了什么吗?这仅适用于主机网络吗?我显然在这里误解了关于 Docker 网络的一些东西......
如果我也尝试使用主机的 IP,它也会失败。
/ # telnet 10.10.1.32 9000
telnet: can't connect to remote host (10.10.1.32): Operation timed out
【问题讨论】: