Docker 1.7.1: Is there a way to provide dynamic information to Dockerfile while building image

时间:2017-04-10 02:23:23

标签: docker dockerfile

I am trying to build an image on Bamboo agent where http_proxy is dynamically set by an administrator and keeps changing.

I need to provide apt-get update and apt-get upgrade -y in Dockerfile which in turn requires access to this dynamically set corporate http_proxy

Any pointers on how to provide this to docker build / Dockerfile?

Basically, I am looking for an option like --build-arg that was introduced in latest docker version.

PS: Upgrading docker version is not an option.

1 个答案:

答案 0 :(得分:1)

One solution that works on 1.7.1 would be to create a file like env:

export http_proxy=<your-proxy>
export https_proxy=<your-proxy>

Then in your Dockerfile COPY it in and then source it before your apt commands in the RUN instruction something like:

# Dockerfile
...
COPY env /scripts/
RUN source /scripts/env && \
    apt-get update
...

Then you just change the proxy values in the env file prior to build. Could do this manually or create a hook type script to do it. The obvious massive downside of this is that you're busting your build cache all the time copying the new file in. I don't see any other options because of your (really) old Docker version though.

相关问题