如何使用Jenkins在HTTP_PROXY后面的Dockerfile构建Docker图像? [英] How to build Docker Images with Dockerfile behind HTTP_PROXY by Jenkins?

查看:377
本文介绍了如何使用Jenkins在HTTP_PROXY后面的Dockerfile构建Docker图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

构建Docker图像在桌面上起作用,没有问题。安装Node.js NPM依赖关系像往常一样工作。然而,当使用诸如Jenkins之类的连续集成服务器,它驻留在公司代理后面时,构建Docker Images失败。



Node.js NPM依赖关系



在构建Node.js pacakges时,克隆GIT依赖关系时无法连接到GIT时,命令 npm install 失败。

  e1ce5e8407d1:已经存在
状态:节点的图像是最新的:0.10.33
---> e1ce5e8407d1
步骤1:运行mkdir -p / usr / src / app
--->使用缓存
---> 965cad0c68b0
步骤2:WORKDIR / usr / src / app
--->使用缓存
---> 4c498f0c07e9
步骤3:COPY package.json / usr / src / app /
---> b0662a8275fb
删除中间容器5aca20551452
步骤4:运行npm安装
--->运行在7ccf9e5362af
npm WARN package.json newww@2.0.0没有README数据
npm WARN package.json依赖关系async-cache存在于依赖关系和devDependencies中,使用'async-cache@^0.1 .5'from dependencies
npm ERR! git clone https://github.com/npm/npm2es.git克隆到裸机库/root/.npm/_git-remotes/https-github-com-npm-npm2es-git-60a75edb...
npm ERR! git clone https://github.com/npm/npm2es.git致命:无法访问https://github.com/npm/npm2es.git/:无法连接到github.com端口443:连接超时



Java Maven,Ruby,Go Docker图像与依赖关系



当构建Java,Ruby或Go容器时,在依赖关系位于公司代理服务器的存储库服务器中的情况也是如此。知道您可以使用HTTP_PROXY环境变量配置Docker,如何正确配置Docker在CI环境中正确构建映像?

解决方案

注意:Docker 1.9 可能会帮助解决这个问题:




  • 问题14634 生成器 - 构建时间参数传递(例如, HTTP_PROXY

  • PR 15182 支持在构建环境中传递构建时变量



):

  docker build --build-arg http_proxy = http://my.proxy.url --build-arg foo = bar< MARK 
FROM busybox
需要http_proxy>的RUN<命令
ARG --description =foo的描述foo
USER $ foo
MARK


Building Docker images works in a desktop without a problem. Installing Node.js NPM dependencies work as usual. However, when using a continuous integration server such as Jenkins that is hosted behind a corporate proxy, the build Docker Images fail.

Node.js NPM Dependencies

While building Node.js pacakges, the command npm install fails when it cannot connect to GIT while cloning GIT dependencies.

e1ce5e8407d1: Already exists
Status: Image is up to date for node:0.10.33
 ---> e1ce5e8407d1
Step 1 : RUN mkdir -p /usr/src/app
 ---> Using cache
 ---> 965cad0c68b0
Step 2 : WORKDIR /usr/src/app
 ---> Using cache
 ---> 4c498f0c07e9
Step 3 : COPY package.json /usr/src/app/
 ---> b0662a8275fb
Removing intermediate container 5aca20551452
Step 4 : RUN npm install
 ---> Running in 7ccf9e5362af
npm WARN package.json newww@2.0.0 No README data
npm WARN package.json Dependency 'async-cache' exists in both dependencies and devDependencies, using 'async-cache@^0.1.5' from dependencies
npm ERR! git clone https://github.com/npm/npm2es.git Cloning into bare repository '/root/.npm/_git-remotes/https-github-com-npm-npm2es-git-60a75edb'...
npm ERR! git clone https://github.com/npm/npm2es.git fatal: unable to access 'https://github.com/npm/npm2es.git/': Failed to connect to github.com port 443: Connection timed out

Java Maven, Ruby, Go Docker Images with Dependencies

The same occurs when building Java, Ruby or Go containers, where dependencies are located in repository servers across your corporate Proxy server.

Knowing that you can configure Docker with HTTP_PROXY environment variable, how to properly configure Docker to properly build images in CI environments?

解决方案

Note: Docker 1.9 might help solve this:

  • "Issue 14634": Builder - Build-time argument passing (e.g., HTTP_PROXY)
  • "PR 15182": Support for passing build-time variables in build context

Usage (proposed):

docker build --build-arg http_proxy=http://my.proxy.url  --build-arg foo=bar <<MARK
FROM busybox
RUN <command that need http_proxy>
ARG --description="foo's description" foo
USER $foo
MARK

这篇关于如何使用Jenkins在HTTP_PROXY后面的Dockerfile构建Docker图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆