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 J
Note: Docker 1.9 might help solve this:
HTTP_PROXY
)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
Starting with Docker 17.07 you can alternatively use the Docker Client configuration file for providing the proxy configuration centrally:
https://docs.docker.com/network/proxy/#configure-the-docker-client
Docker has multiple ways to set proxies that take effect at different times.
If your docker build
has to retrieve a base image through a proxy, you'll want to specify build-arg
s:
docker build --build-arg HTTP_PROXY=$http_proxy \
--build-arg HTTPS_PROXY=$http_proxy --build-arg NO_PROXY="$no_proxy" \
--build-arg http_proxy=$http_proxy --build-arg https_proxy=$http_proxy \
--build-arg no_proxy="$no_proxy" -t myContainer /path/to/Dockerfile/directory
where $http_proxy
and $no_proxy
were set in my bashrc. I used both HTTP_PROXY
and http_proxy
because different utilities will check different variables (curl
checks both, wget
only checks the lowercase ones, etc).
If your docker build
has a RUN curl/wget/etc
command that has to go through the proxy, you'll need to specify an environment variable inside your docker image:
ENV https_proxy=http://proxy-us02.company.com:8080
ENV http_proxy=http://proxy-us02.company.com:8080
ENV HTTP_PROXY=http://proxy-us02.company.com:8080
ENV HTTPS_PROXY=http://proxy-us02.company.com:8080
ENV no_proxy="localhost,localdomain,127.0.0.1,etc"
ENV NO_PROXY="localhost,localdomain,127.0.0.1,etc"
If you don't want this environment variable inside your image at runtime, you can remove all these at the end:
RUN unset http_proxy https_proxy no_proxy HTTP_PROXY HTTPS_PROXY NO_PROXY
I had a problem when corporate network was not allowing to download and setup docker image so n/w gave http proxy information. while running docker image build I passed the variable and it worked without any issues.
docker build --build-arg http_proxy="http://userid:pwd@iaisystem.com:8080" - < Dockerfile
We are doing ...
ENV http_proxy http://9.9.9.9:9999
ENV https_proxy http://9.9.9.9:9999
and at end of dockerfile ...
ENV http_proxy ""
ENV https_proxy ""
This, for now (until docker introduces build env vars), allows the proxy vars to be used for build without publicly exposing them
You can use a transparent proxy, as described in:
https://jpetazzo.github.io/2014/06/17/transparent-squid-proxy-docker/
docker run --net host jpetazzo/squid-in-a-can
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to 3129