DockerFile present in a particular project is considered for this use case .As a part of this docker file , proxy settings are present in two places, one is with env and the other is with run command and both of them has to be configurable and should not be hard coded in the docker file,so that docker container can be used in any environment.
Basically to fix this we can make use of –build-arg and ARG options provided by Docker as follows
Following is one way of sending the proxy settings at runtime.
docker build -t images.dockhub-atp.abc.com/teamcity:v0.2 . –build-arg http_proxy=http://www-proxy-xyz.us.abc.com:80 –build-arg https_proxy=http://www-proxy-abc.us.xyz.com:80 –build-arg no_proxy=abccorp.com,localhost,127.0.0.1
with the above step, Following ENV can be removed from the DockerFile.
ENV http_proxy http://www-proxy-atp.us.xyz.com:80
ENV https_proxy http://www-proxy-ran.us.xyz.com:80
ENV no_proxy .abc.com,.abccorp.com,localhost,127.0.0.1
Secondly, With respect to the following hard coded proxy settings we can make use of ARG.
RUN echo ‘export http_proxy=http://www-proxy-abc.us.abc.com:80’ >> /etc/default/docker \
&& echo ‘export https_proxy=http://www-proxy-abc.us.abc.com:80’ >> /etc/default/docker \
&& echo ‘export no_proxy=.abc.com,.xyzcorp.com,localhost,127.0.0.1’ >> /etc/default/docker \
&& echo ‘export NO_PROXY=.abc.com,.zyaccorp.com,localhost,127.0.0.1’ >> /etc/default/docker \
&& echo ‘export HTTPS_PROXY=http://www-proxy-hqdc.us.abc.com:80’ >> /etc/default/docker \
&& echo ‘export HTTP_PROXY=http://www-proxy-hqdc.us.abc.com:80’ >> /etc/default/docker \
Replaced above with the following.
ARG http_proxy
ARG no_proxy
#Add proxy conf for docker within teamcity agent
RUN echo ‘export http_proxy=$http_proxy’ >> /etc/default/docker \
&& echo ‘export https_proxy=$http_proxy’ >> /etc/default/docker \
&& echo ‘export no_proxy=$no_proxy’ >> /etc/default/docker \
&& echo ‘export NO_PROXY=$no_proxy’ >> /etc/default/docker \
&& echo ‘export HTTPS_PROXY=$http_proxy’ >> /etc/default/docker \
&& echo ‘export HTTP_PROXY=$http_proxy’ >> /etc/default/docker \
http_proxy and no_proxy are passed at runtime while building the docker image.