You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Docker容器内curl无法访问:连接172.17.0.1的9999端口被拒绝

问题解决:node:13容器内curl异常连接主机9999端口

问题现象

在node:13容器内执行curl -v google.com时出现连接拒绝错误,curl尝试连接主机IP(172.17.0.1)的9999端口,而非直接请求google.com的IP:

root@01f9a4b98e94:/# curl -v google.com
* Rebuilt URL to: google.com/
*   Trying 172.17.0.1...
* TCP_NODELAY set
* connect to 172.17.0.1 port 9999 failed: Connection refused
* Failed to connect to 172.17.0.1 port 9999: Connection refused
* Closing connection 0

添加--ipv4选项后问题依旧,但ping google.com可正常解析并连通:

root@b1922f6cac72:/# ping google.com
PING google.com (142.250.204.14) 56(84) bytes of data.
64 bytes from syd09s25-in-f14.1e100.net (142.250.204.14): icmp_seq=1 ttl=116 time=35.3 ms

该问题仅在node:13容器中出现,其他容器无异常。

原因分析

curl的异常行为由代理配置导致:容器内的curl被设置了HTTP/HTTPS代理,指向主机的9999端口,但该端口未提供代理服务,因此连接被拒绝。ping不受代理规则影响,所以能正常工作。

解决步骤

  1. 检查代理环境变量
    在容器内执行以下命令,确认是否存在代理配置:

    echo $http_proxy $https_proxy $ALL_PROXY
    

    如果输出包含172.17.0.1:9999,说明环境变量中配置了代理。

  2. 临时清除代理
    执行以下命令清空代理变量,再测试curl:

    unset http_proxy https_proxy ALL_PROXY
    curl google.com
    
  3. 检查curl配置文件
    查看系统级或用户级的curl配置文件,确认是否有硬编码的代理设置:

    cat /etc/curlrc
    cat ~/.curlrc
    

    如果发现类似proxy = 172.17.0.1:9999的配置,注释或删除该行。

  4. 启动容器时排除代理继承
    如果主机系统本身设置了代理环境变量,docker run会默认继承这些变量。启动容器时可以手动清空:

    docker run -it --rm --env http_proxy= --env https_proxy= --env ALL_PROXY= node:13 /bin/bash
    

内容的提问来源于stack exchange,提问作者WitHeld

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 06:10:36