docker - 为 Docker Dind 服务设置代理
问题描述
我正在使用 Gitlab CI/CD 管道,并且正在尝试使发布作业正常工作。
我的网络受公司政策保护,所以我需要使用代理。我为我的 Docker 设置了代理配置。它运行良好,直到docker build
工作被执行。
我的发布工作如下所示:
publish_test:
stage: publish
image: docker:19.03.1
only:
- test
services:
- docker:19.03.1-dind
variables:
IMAGE: ${IMAGE}
before_script:
- mkdir tmp
- cp docker/Dockerfile build/libs/backend_v2-*.jar tmp
- cd tmp
- echo ${CI_REGISTRY_PASSWORD} | docker login ${CI_REGISTRY} -u ${CI_REGISTRY_USER} --password-stdin
script:
- docker pull ${IMAGE} || true
- docker tag ${IMAGE} ${IMAGE}-backup || true
- docker push ${IMAGE}-backup || true
- echo $CI_REGISTRY
- docker build -t ${IMAGE} .
- docker push ${IMAGE}
cache:
key: ${CI_COMMIT_REF_NAME}
policy: pull
paths:
- build/
问题出在这里:docker build -t ${IMAGE} .
由于连接错误,他无法拉取 Docker 映像:
Step 1/4 : FROM azul/zulu-openjdk-alpine:11
Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
ERROR: Job failed: exit code 1
到目前为止,我已经尝试了多种解决方案,但没有一个对我有用:
1. 尝试将代理变量添加到 Gitlab 变量中并将代理配置放入这项工作中,如下所示:
- export http_proxy=${HTTP_PROXY};
- export https_proxy=${HTTP_PROXY};
- export no_proxy=${NO_PROXY};
- 尝试使用
build-arg
参数:
docker build --progress --build-arg ${HTTP_PROXY} --build-arg ${HTTPS_PROXY} --build-arg ${NO_PROXY} -t ${IMAGE} .
- 我在 Gitlab 文档中找到了我的案例 - https://docs.gitlab.com/runner/configuration/proxy.html#proxy-settings-when-using-dind-service。尝试按照那里的指示进行操作,但没有成功。
我怎样才能让它为我工作?我需要为此 Docker 构建作业设置代理设置,以便它可以提取必要的 Docker 映像。任何帮助表示赞赏。
解决方案
- 您不需要重新导出配置为 GitLab 变量的环境。将脚本
env | grep proxy
或添加env | grep PROXY
到您的管道以查看是否存在环境。 - 假设您的代理环境看起来像这个
HTTP_PROXY=http://127.0.0.1:3001
构建命令应该是docker build --progress --build-arg http_proxy=${HTTP_PROXY} ...
看起来你使用错误的构建参数--build-arg ${HTTP_PROXY}
应该是--build-arg http_proxy=${HTTP_PROXY}
和相同https_proxy
的no_proxy
。
推荐阅读
- java - 如何监听 Firebase 数据库集合的变化?
- django - 无法在 graphene_django 中获取 OneToOne 关系查询的值
- php - 如果有任何方法可以为整个 hls 流文件夹创建签名 url
- r - 根据 R 数据表中的最小和最大时间戳选择一列中的值
- jquery - 在 gmap 上绘制和编辑多边形节点,并将检索点作为 Angularjs 上的数组
- python - 让python在文件管理器中读取带有“打开方式”功能的文件(Python)
- c# - 为什么我从相同的硬编码字符串值与来自 db 的字符串相比得到不同的结果?
- javascript - Codeigniter 和 SCSS,
- machine-learning - 减少分类机器学习模型中特征的最佳方法
- java - 通过在列标题中传递不同列的 ORDER BY