Docker proxy Configurations

Dheeraj kumar
2 min readFeb 25, 2021

Most people often find it difficult to set up docker and configure it when running behind any proxy server, if you’re trying to run Docker without having direct access to the web you have to configure the docker daemon to use a proxy server. Without it, you won’t be able to pull or push any image.

The image above is for windows docker proxy settings and you will have the same settings with the Linux servers as well, with the steps mentioned below.

I see a lot of tutorials on the internet describing how to apply the proxy in the docker configuration. but to understand what proxy settings you need according to your requirement is really important as well.

The difference between the proxy settings used by the docker daemon is described below.

USECASE 1: /etc/systemd/system/docker.service.d/http-proxy-conf
#this proxy settings are required when you want to pull or push docker images from the internet.
USECASE 2: ~/.docker/config.json file or /etc/docker/daemon.json
# this proxy setting is required when you want to enable internet in your running containers. i.e all the containers running in your server will be having these proxy settings in them and you will be access internet in your containers without any problem.

For USE CASE 1: if you getting an error like this when running this command or trying to push or pull any docker images.

$ docker pull mongo:latest
Unable to find image 'mongo:latest' locally
docker: Error response from daemon: Get https://registry-1.docker.io/v2/: dial tcp 34.201.196.144:443: connect: connection refused.

The problem here is that your docker daemon doesn't have connectivity to the internet so you have to setup a proxy in the daemon configuration which you generally use to connect your server to the internet.

STEP 1: Create a configuration file /etc/systemd/system/docker.service.d/http-proxy.conf with following content:

[Service]
Environment="HTTP_PROXY=http://10.9.2.63:8000/" "HTTPS_PROXY=http://10.9.2.63:8000/"

STEP 2: Reload systemd daemon

$ sudo systemctl daemon-reload

STEP 3: Restart docker service

$ sudo systemctl restart docker.service

For USE CASE 2:

STEP 1: Create a configuration file

~/.docker/config.json or /etc/docker/daemon.json with following content:

{ "proxies": 
{ "default":
{ "httpProxy": "http://10.9.2.63:8000/",
"httpsProxy": "http://10.9.2.63:8000/"
}
}
}

STEP 2: Reload systemd daemon

$ sudo systemctl daemon-reload

STEP 3: Restart docker service

$ sudo systemctl restart docker.service

Also, you can use this shell script, which will set up your proxy setting on system-level as well as on docker daemon.

wget -https://raw.githubusercontent.com/djay21/Automation_Scripts/master/proxy_setup.sh | sudo bash

and you are all set to run docker images & containers without any issues.

--

--