在 windows 上构建 docker 图像 |代理问题

Build docker image on windows | proxy issue

我正在尝试从 docker 容器中安装 curl 但失败并出现以下错误,我尝试设置代理 - 不行

尝试的步骤:

请进一步告知 - 谢谢

$ docker 运行 -ti --env HTTPS_PROXY="" alpine:latest - 有效,我可以进去了。

# apk add --no-cache curl 
fetch https://dl-cdn.alpinelinux.org/alpine/v3.13/main/x86_64/APKINDEX.tar.gz 
WARNING: Ignoring https://dl-cdn.alpinelinux.org/alpine/v3.13/main: Permission denied 
fetch https://dl-cdn.alpinelinux.org/alpine/v3.13/community/x86_64/APKINDEX.tar.gz 
WARNING: Ignoring https://dl-cdn.alpinelinux.org/alpine/v3.13/community: temporary error (try again later) 
ERROR: unable to select packages: 
  curl (no such package): 
    required by: world[curl]

下载证书:example.crt

复制example.crt到/etc/ssl/certs/example.crt容器内

将example.crt的内容添加到/etc/ssl/certs/ca-certificates.crt

cat /etc/ssl/certs/example.crt >> /etc/ssl/certs/ca-certificates.crt

将环境 HTTPS_PROXY 变量设置为 http://{proxy}:{port}

export HTTPS_PROXY=http://{proxy}:{port}

运行 apk 更新或从外部资源安装其他包

Docker 文件

 FROM alpine:latest

 # This could also be passed as a build argument
 ENV HTTPS_PROXY=http://{proxy}:{port}

 COPY example.crt /etc/ssl/certs/example.crt
 RUN cat /etc/ssl/certs/example.crt >> /etc/ssl/certs/ca-certificates.crt

 RUN apk update

这解决了问题。