SoFunction
Updated on 2025-03-09

This article explains how to configure docker to pull images through proxy server

Preface

If the environment where docker is located is connected to the Internet through a proxy server, then some configuration is required to enable docker to pull the mirror normally from the external network. However, it is not enough to just configure environment variables. This article combines existing documents to introduce how to configure a proxy server to enable docker to pull images normally.

The docker version used in this article is

docker --version
Docker version 25.0.1, build cb74dfc

Problem phenomenon

If you don't configure the proxy server and pull the image directly, docker will directly try to connect to the image repository, and the connection timeout will be reported. As shown below:

$ docker pull busybox
Using default tag: latest
Error response from daemon: Get /v2/: net/http: request canceled 
while waiting for connection ( exceeded while awaiting headers)

1. Create a dockerd-related systemd directory. The configuration in this directory will override the default configuration of dockerd.

$ sudo mkdir -p /etc/systemd/system/

Create a new configuration file/etc/systemd/system//, this file will contain environment variables

[Service]
Environment="HTTP_PROXY=:80"
Environment="HTTPS_PROXY=:443"

If you have built a private mirror repository yourself and need dockerd to bypass the proxy server direct connection, then configure the NO_PROXY variable:

[Service]
Environment="HTTP_PROXY=:80"
Environment="HTTPS_PROXY=:443"
Environment="NO_PROXY=,10.10.10.10,*."

MultipleNO_PROXYThe values ​​of variables are separated by commas, and wildcard characters (*) can be used. In extreme cases, ifNO_PROXY=*, then all requests will not go through the proxy server.

2. Reload the configuration file and restart dockerd

$ sudo systemctl daemon-reload
$ sudo systemctl restart docker

3. Check to confirm that the environment variables have been correctly configured:

$ sudo systemctl show --property=Environment docker

View configuration items from the results of docker info.

After this configuration, the docker image should be pulled normally.

Summarize

This is the article about how to configure docker to pull images through proxy servers. For more related docker to pull images through proxy servers, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!