因此,我不得不通过反复试验来解决这个问题,因为许多人解释说您可以通过ARG
->,ENV
但是它并不总是有效,因为在FROM
标签之前还是之后定义ARG都至关重要。
下面的示例应该清楚地说明这一点。我的主要问题原本是我所有的ARGS的被定义之前,FROM
这导致所有ENV
要始终不确定。
# ARGS PRIOR TO FROM TAG ARE AVAIL ONLY TO FROM for dynamic a FROM tag
ARG NODE_VERSION
FROM node:${NODE_VERSION}-alpine
# ARGS POST FROM can bond/link args to env to make the containers environment dynamic
ARG NPM_AUTH_TOKEN
ARG EMAIL
ARG NPM_REPO
ENV NPM_AUTH_TOKEN ${NPM_AUTH_TOKEN}
ENV EMAIL ${EMAIL}
ENV NPM_REPO ${NPM_REPO}
# for good measure, what do we really have
RUN echo NPM_AUTH_TOKEN: $NPM_AUTH_TOKEN && \
echo EMAIL: $EMAIL && \
echo NPM_REPO: $NPM_REPO && \
echo $HI_5
# remember to change HI_5 every build to break `docker build`'s cache if you want to debug the stdout
..... # rest of whatever you want RUN, CMD, ENTRYPOINT etc..
docker run -e http_proxy http://1.2.3.4:3128 -e https_proxy 1.2.3.4:3129
什么?docker run
docs.docker.com/reference/commandline/run