【发布时间】:2018-06-06 12:37:15
【问题描述】:
我有一个运行 Caddy 的 docker 容器和另一个 Web 服务器。
在我的Dockerfile 我有
EXPOSE 80 10240 # 10240 is the port of the other webserver.
我是这样运行 docker 的(不要问我为什么需要 EXPOSE 和 -p)。
docker run -p 80:80 -p 10240:1024 -it <hash>
这将启动两个服务器。在我的主机上(它是 Mac 顺便说一句)我可以连接到 localhost:10240 很好。但是,如果我连接到 localhost:80,我会得到一个空响应(断开连接)。
docker 容器中的 Netstat 显示:
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:10240 0.0.0.0:* LISTEN 19/node
tcp6 0 0 :::80 :::* LISTEN 9/caddy
这就是它开始变得奇怪的地方。如果我 curl -L localhost 在 docker 容器内,它工作正常 - 我从 10240 服务器获取网页。
如果我在 docker 容器中 curl -L 127.0.0.1,它会返回 404 Site 127.0.0.1 is not served on this interface。好吧好吧。
如果我在外部容器中curl -L 127.0.0.1,它也返回404 Site 127.0.0.1 is not served on this interface。所以不知何故,我的请求通过了,但 Caddy 丢弃了来自容器外部的 localhost 请求,而不是来自容器内部。我启用了日志记录,但它什么也没打印。
谁能告诉我到底发生了什么?所有这些 docker 端口转发的东西都是荒谬的。
这是我的 Caddyfile(我已经尝试了大约 10 亿个 localhost、127.0.0.1 等的其他组合):
localhost:80
bind 0.0.0.0
proxy / 127.0.0.1:10240
【问题讨论】:
-
这是一个错字“docker run -p 80:80 -p 10240:1024 -it
”吗?这样,您将发布端口 1024 而不是 10240... -
啊,是的,这是一个错字。我实际上确实使用了 10240。