无法从 docker 容器内部发出 https 请求,但它在主机上运行良好

无法从 docker 容器内部发出 https 请求,但它在主机上运行良好

在我的应用程序中,我需要从 Docker 容器向公司的内部 JIRA 实例发出请求,但请求总是超时。我可以从容器内部向其他站点发出 https 请求,也可以从主机向 JIRA 实例发出 https 请求。

我尝试将端口“443:443”传递给我需要发出请求的容器,但没有帮助。

当我在主机上 curl 该 URL 时,输出的开头是:

curl -v [URL]
* About to connect() to proxy [proxy address] port 8080 (#0)
*   Trying [proxy address]...
* Connected to [proxy address] ([proxy address]) port 8080 (#0)
* Establish HTTP proxy tunnel to [URL]:443
> CONNECT [URL]:443 HTTP/1.1
> Host: [URL]:443
> User-Agent: curl/7.29.0
> Proxy-Connection: Keep-Alive
>
< HTTP/1.1 200 Connection Established
< Proxy-Agent: Fortinet-Proxy/1.0
<
* Proxy replied OK to CONNECT request
[rest of the successful response]

之后,我将容器中的 http_proxy 和 https_proxy 环境变量设置为上述片段中的代理地址。尝试从容器中 curl 相同的 URL 后,我得到了以下输出:

*   Trying [proxy address]...
* TCP_NODELAY set
* Connected to (nil) ([proxy address]) port 8080 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*   CAfile: none
  CApath: /etc/ssl/certs
* TLSv1.2 (OUT), TLS header, Certificate Status (22):
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* Operation timed out after 300000 milliseconds with 0 out of 0 bytes received
* Curl_http_done: called premature == 1
* stopped the pause stream!
* Closing connection 0
curl: (28) Operation timed out after 300000 milliseconds with 0 out of 0 bytes received

我还有一个想法,我认为我可以使用 docker 网络中的主机 ip 作为代理来发出请求,但我无法让它工作。这可能吗?

编辑:我错了,当我找到解决方案时没有更新。就我而言,这与端口转发有关。我公司的一位更有经验的工程师帮助了我,他给出了一个命令,让它工作了:

iptables -l FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu

我没有进一步调查每个标志的作用以及根本原因是什么,因为我已经受够了所有这些东西。这在重新启动主机之前一直有效,但有一种方法可以使 iptables 更改永久生效。

相关内容