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

自托管Azure DevOps Agent容器无法访问主机localhost应用的解决方法

解决自托管Azure DevOps代理容器无法访问服务器localhost的问题

核心问题是:使用--network host模式时,容器内的localhost指向容器自身,而非宿主机的localhost,和Azure DevOps代理本身的配置无关。以下是具体解决方法:

  • 替换localhost为宿主机实际IP
    直接用宿主机的内网IP(或公网IP,视网络场景)代替localhost。可以通过以下命令获取宿主机IP:

    • Linux:执行hostname -I
    • Windows:执行ipconfig
      容器内访问服务时,用这个IP替代localhost即可。
  • 使用Docker内置的宿主机访问域名(Docker 18.03+)

    • Windows/macOS环境:容器内直接用host.docker.internal代替localhost,默认会解析到宿主机IP。
    • Linux环境:启动容器时添加--add-host=host.docker.internal:host-gateway参数,命令示例:
      docker run --rm --network host --add-host=host.docker.internal:host-gateway <your-agent-image>
      

    之后容器内通过host.docker.internal就能访问宿主机服务。

  • 检查宿主机防火墙规则
    确保宿主机防火墙允许Docker容器所在网段的流量访问目标服务的端口。比如服务运行在8080端口,需开放该端口给容器对应的IP段。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.24 21:51:24