我有一个运行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
这就是它开始变得奇怪的地方。如果我在docker容器中使用curl -L localhost
,它工作得很好--我从10240服务器上得到了网页。
如果我从停靠容器中执行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
。因此,不知何故,我的请求是通过的,但凯迪会从容器外部丢弃localhost
请求,而不是从容器内部。我启用了日志记录,但它不打印任何内容。
谁能告诉我到底是怎么回事?所有这些对接端口转发的东西都是荒谬的。
这是我的Caddyfile (我已经尝试了大约十亿个其他的localhost
、127.0.0.1
等组合):
localhost:80
bind 0.0.0.0
proxy / 127.0.0.1:10240
https://stackoverflow.com/questions/50720600
复制相似问题