Using proxy in Dockerfile

:heavy_exclamation_mark: This post is older than a year. Consider some information might not be accurate anymore. :heavy_exclamation_mark:

Using docker in companies with tight security involves using proxies for pulling the image data of dockerhub. In my previous post I illustrated several ways how to enable docker using the proxy. I assume you are using a central local proxy auth server like CNTLM. So no bypassing any auth data. In the Dockerfile itself, it can be used like this:

ENV http_proxy
ENV https_proxy

Most programs like curl, wget, apt (Debian) or apk (Alpine Linux) honor that. So something like this should work:

RUN apk update && apk add wget

Some programs however have dedicated options like gpg --keyserver <keyserver-name> --keyserver-options http-proxy=<proxy-data>.

RUN set -x \
     && apk add --no-cache --virtual .gosu-deps \
         dpkg \
         gnupg \
         openssl \
     && dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')" \
     && wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch" \
     && wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch.asc" \
     && export GNUPGHOME="$(mktemp -d)" \
     && gpg --keyserver ha.pool.sks-keyservers.net --keyserver-options http-proxy=$http_proxy --recv-keys                       B42F6819007F00F88E364FD4036A9C25BF357DD4 \
     && gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu \
     && rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc \
     && chmod +x /usr/local/bin/gosu \
     && gosu nobody true \
     && apk del .gosu-deps
Please remember the terms for blog comments.