我想将一个http_proxy环境变量添加到nodejs alpine docker镜像中。
Dockerfile看起来像这样
FROM node:6-alpine
RUN export
RUN export https_proxy='http://myproxy:8080'
RUN export http_proxy='http://myproxy:8080'
RUN export
运行时的输出
docker build -t myimage:latest .
看起来像这样
Step 1/5 : FROM node:6-alpine
---> 66cf88e4fc20
Step 2/5 : RUN export
---> Running in 61f5bda7989d
export HOME='/root'
export HOSTNAME='26ba10d264c2'
export NODE_VERSION='6.9.5'
export NPM_CONFIG_LOGLEVEL='info'
export PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
export PWD='/'
export SHLVL='1'
---> f04aeb89f7d0
Removing intermediate container 61f5bda7989d
Step 3/5 : RUN export https_proxy='http://myproxy:8080'
---> Running in 895d13321da8
---> 6a8aaa9639a9
Removing intermediate container 895d13321da8
Step 4/5 : RUN export http_proxy='http://myproxy:8080'
---> Running in 19910745f212
---> 1de5b4fb2b2e
Removing intermediate container 19910745f212
Step 5/5 : RUN export
---> Running in e5d186b66385
export HOME='/root'
export HOSTNAME='26ba10d264c2'
export NODE_VERSION='6.9.5'
export NPM_CONFIG_LOGLEVEL='info'
export PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
export PWD='/'
export SHLVL='1'
---> 0aa0f97555bf
Removing intermediate container e5d186b66385
Successfully built 0aa0f97555bf
正如您所看到的,shell上的导出尚未完成!
当我在新构建的图像中打开一个shell并手动执行命令时,它会起作用。
> docker run myimage:latest sh
/ # export https_proxy='http://myproxy:8080'
/ # export http_proxy='http://myproxy:8080'
/ # export
export HOME='/root'
export HOSTNAME='a759e3d30481'
export NODE_VERSION='6.9.5'
export NPM_CONFIG_LOGLEVEL='info'
export PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
export PWD='/'
export SHLVL='1'
export TERM='xterm'
export http_proxy='http://myproxy:8080'
export https_proxy='http://myproxy:8080'
那么我做错了什么?
答案 0 :(得分:1)
这不是在Dockerfile中定义ENV变量的正确方法,更好地使用ENV
查看文档https://docs.docker.com/engine/reference/builder/#/env
顺便说一句,将你的RUN分组,看看解释它的文档
https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/