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

在Windows Server上构建Linux容器时如何安装curl?

在Windows Server容器中安装curl的可行方案

针对Windows Server容器环境,替代Linux下apt-get安装curl的方法主要有以下几种,根据你使用的基础镜像类型选择:

1. Windows Server Core 镜像手动安装

如果基于mcr.microsoft.com/windows/servercore系列镜像,可通过PowerShell下载官方预编译包完成安装,在Dockerfile中添加:

RUN powershell -Command \
    Invoke-WebRequest -Uri https://curl.se/windows/dl-8.8.0_6/curl-8.8.0_6-win64-mingw.zip -OutFile curl.zip -UseBasicParsing ; \
    Expand-Archive -Path curl.zip -DestinationPath C:\ ; \
    Copy-Item -Path C:\curl-8.8.0_6-win64-mingw\bin\curl.exe -Destination C:\Windows\System32 ; \
    Remove-Item -Path curl.zip, C:\curl-8.8.0_6-win64-mingw -Recurse -Force
  • -UseBasicParsing参数用于避免PowerShell在解析网页时出现的兼容性问题
  • 将curl.exe复制到C:\Windows\System32可实现全局调用
  • 最后清理临时文件以减小镜像体积

2. Windows Nano Server 镜像适配安装

Nano Server镜像更轻量化,系统目录权限特殊,可调整为以下指令:

RUN powershell -Command \
    Invoke-WebRequest -Uri https://curl.se/windows/dl-8.8.0_6/curl-8.8.0_6-win64-mingw.zip -OutFile curl.zip -UseBasicParsing ; \
    Expand-Archive curl.zip -DestinationPath C:\ ; \
    Move-Item C:\curl-8.8.0_6-win64-mingw\bin\curl.exe C:\ ; \
    Remove-Item -Path curl.zip, C:\curl-8.8.0_6-win64-mingw -Recurse -Force

后续调用时可直接用C:\curl.exe,或通过SET PATH=%PATH%;C:\将根目录加入环境变量。

3. 使用预装curl的官方镜像

部分Windows Server Core镜像版本已预装curl,可直接使用并验证:

FROM mcr.microsoft.com/windows/servercore:ltsc2022
RUN curl --version

注意:不同镜像版本预装情况不同,建议先执行验证命令确认。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.21 01:11:06