Docker Proxy Configuration

Background

Due to certain domains being inaccessible from the company network, we need to go through a proxy to access the external internet. Most of the time, setting the following environment variables should suffice:

1
2
export http_proxy="http://proxy_ip:proxy_port"
export https_proxy="http://proxy_ip:proxy_port"

However, there are cases where different services require specific proxy settings. For instance, Python’s package manager pip requires the --proxy parameter during installation.

Initially, I didn’t realize that Docker also needed its own proxy configuration. When using the docker pull command, I kept encountering this error:

1
⚠️ Error response from daemon: Get "https://registry-1.docker.io/v2/": read tcp x.x.x.x:x->y.y.y.y:y: read: connection reset by peer

Solution

After some investigation, I found out that Docker’s proxy settings need to be added via a configuration file, specifically for CentOS, create the file /etc/systemd/system/docker.service.d/http-proxy.conf:

1
2
mkdir -p /etc/systemd/system/docker.service.d
vim /etc/systemd/system/docker.service.d/http-proxy.conf
1
2
3
[Service]
Environment="HTTP_PROXY=http://proxy_ip:proxy_port"
Environment="HTTPS_PROXY=http://proxy_ip:proxy_port"

Then, restart the Docker service:

1
2
systemctl daemon-reload
systemctl restart docker

Now, you should be able to successfully download Docker images using docker pull!

References

0%