Adding Proxy to Your Docker Service

zorexsalvo profile image Zorex Salvo ・2 min read

This is only a personal note for my docker service configuration in office network proxy.


Have you ever experienced slow docker build even though your machine is on a network proxy?

Me? always.

Then this idea came from one of our interns. At first, what he did was to add environment variables inside his Dockerfile.

Seems a bright idea huh? but it is not a good one really because his image can be built only IF he is in our office network.

There came a problem where he did not know what went wrong with his build on docker hub because "It ran on local machine". The problem was the http_proxy cannot be resolved by docker hub.

Thats the exact opposite of the Build, Ship, and Run Any App, Anywhere catchphrase of Docker. It didn't even pass the build part kekeke.

Then another idea came up, what if we add the proxy on the docker itself so that we do not have to specify the environment variable HTTP_PROXY to the Dockerfile. That is a great idea!

Here's how to do that:

First, create a systemd drop in directory

mkdir /etc/systemd/system/docker.service.d/

Then, create http-proxy.conf

touch /etc/systemd/system/docker.service.d/http-proxy.conf

## http-proxy.conf

Then, Flush Changes by doing:

sudo systemctl daemon-reload

And lastly, Restart Docker

sudo systemctl restart docker

To check if the environment variable is really added on your docker service, do docker info.

And pooof, notice the change in speed in your docker build!


Editor guide
tnodet profile image
Tanguy Nodet

Thanks a lot, I couldn't figure out how to configure proxy for Docker on CentOS 7 guest in VirtualBox, and it works like a charm!