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

Docker构建Windows镜像时curl 443端口连接超时错误求助

解决Docker构建Windows镜像时curl无法连接aka.ms的问题

针对你遇到的curl: (28) Failed to connect to aka.ms port 443 after 21099 ms: Couldn't connect to server超时问题,可尝试以下几种方案:

1. 确保容器内DNS配置正确

主机设置DNS不代表容器会自动继承,可直接在构建时指定容器DNS:

docker build --dns 8.8.8.8 --dns 8.8.4.4 -t your-image .

也可以在Dockerfile中添加容器内DNS配置命令(适用于Windows Server Core镜像):

RUN netsh interface ip set dns "Ethernet0" static 8.8.8.8

先进入基础镜像测试网络连通性,确认DNS解析是否正常:

docker run -it --rm mcr.microsoft.com/windows/servercore:ltsc2019 cmd
# 执行以下命令测试
nslookup aka.ms
ping aka.ms

2. 替换curl为PowerShell下载命令

Windows容器中的curl版本可能存在兼容性问题,改用PowerShell的Invoke-WebRequest更适配Windows环境,修改Dockerfile中的下载部分:

# 临时切换到PowerShell执行下载
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

RUN `
    # 用PowerShell下载构建工具引导程序
    Invoke-WebRequest -Uri https://aka.ms/vs/17/release/vs_buildtools.exe -OutFile vs_buildtools.exe -TimeoutSec 30; `
    # 安装Build Tools
    Start-Process -FilePath .\vs_buildtools.exe -ArgumentList '--quiet --wait --norestart --nocache --installPath "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools" --add Microsoft.VisualStudio.Workload.AzureBuildTools --remove Microsoft.VisualStudio.Component.Windows10SDK.10240 --remove Microsoft.VisualStudio.Component.Windows10SDK.10586 --remove Microsoft.VisualStudio.Component.Windows10SDK.14393 --remove Microsoft.VisualStudio.Component.Windows81SDK' -Wait; `
    # 清理文件
    Remove-Item vs_buildtools.exe -Force

# 切回默认cmd shell
SHELL ["cmd", "/S", "/C"]

3. 检查代理与防火墙设置

  • 如果你的网络需要代理,在Dockerfile中添加代理环境变量:
    ENV HTTP_PROXY=http://proxy-address:port
    ENV HTTPS_PROXY=http://proxy-address:port
    ENV NO_PROXY=localhost,127.0.0.1
    
  • 检查主机防火墙是否拦截了容器的出站443请求,可临时关闭防火墙测试是否解决问题。

4. 更换基础镜像版本

尝试使用ltsc2022版本的基础镜像(你Dockerfile中已注释),新版本镜像包含更新的网络组件与系统补丁,可能修复连接问题:

FROM mcr.microsoft.com/windows/servercore:ltsc2022

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.13 21:15:24