[英]curl hangs in docker, but not on host machine
We're currently having an issue where curl bigquery.googleapis.com
sometimes hangs indefinitely inside a ubuntu:20.04
local docker container, but always works (returns a 404) on the host macOS machine and in production.我们目前遇到的问题是
curl bigquery.googleapis.com
有时会在ubuntu:20.04
本地 docker 容器内无限期挂起,但在主机 macOS 机器上和生产环境中始终有效(返回 404)。 The container is running a Python Flask application.容器正在运行 Python Flask 应用程序。
Some observations:一些观察:
curl bigquery.googleapis.com
works when the container initializes, but trying again ~10 mins later hangs.curl bigquery.googleapis.com
在容器初始化时工作,但在大约 10 分钟后再次尝试挂起。 Eventually, the command will work again and curl -v
shows it's trying to connect to a different IP.curl -v
显示它正在尝试连接到不同的 IP。curl servicemanagement.googleapis.com
) works fine.curl servicemanagement.googleapis.com
)的连接工作正常。 Interestingly, doing netstat
on the host machine shows all connections as ESTABLISHED
, but doing netstat
inside the container shows them as SYN_SENT
.有趣的是,在主机上执行
netstat
所有连接显示为ESTABLISHED
,但在容器内执行netstat
会将它们显示为SYN_SENT
。
We hypothesize that the connection is being kept alive on the host, but is killed in the container.我们假设连接在主机上保持活动状态,但在容器中被终止。 Or, certain ACKs aren't being forwarded correctly to the container for some reason.
或者,由于某种原因,某些 ACK 没有正确转发到容器。
netstat
on macOS macOS 上的
netstat
netstat
inside container容器内的
netstat
curl -v output curl -v 输出
root@cf8bd850e9ab:/code# curl -v bigquery.googleapis.com
* Trying 142.251.35.170:80...
* TCP_NODELAY set
* Trying 2607:f8b0:4006:81e::200a:80...
* TCP_NODELAY set
* Immediate connect fail for 2607:f8b0:4006:81e::200a: Cannot assign requested address
* Trying 2607:f8b0:4006:81e::200a:80...
* TCP_NODELAY set
* Immediate connect fail for 2607:f8b0:4006:81e::200a: Cannot assign requested address
* Trying 2607:f8b0:4006:81e::200a:80...
* TCP_NODELAY set
* Immediate connect fail for 2607:f8b0:4006:81e::200a: Cannot assign requested address
* Trying 2607:f8b0:4006:81e::200a:80...
* TCP_NODELAY set
* Immediate connect fail for 2607:f8b0:4006:81e::200a: Cannot assign requested address
Additional output:附加输出:
netstat -p
: https://pastebin.com/sKQ23yah netstat -p
: https ://pastebin.com/sKQ23yahcurl --ipv4
: https://pastebin.com/3N7Q6aB4 curl --ipv4
: https ://pastebin.com/3N7Q6aB4您可以在使用--dns
标志运行容器时指定 DNS,也可以通过在/etc/docker/daemon.json
中添加一个条目来配置它,这可能有助于解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.