Due to well-known reasons, using Docker in mainland China often results in slow or failed image pulls. This article covers two main solutions: using domestic mirror acceleration and configuring proxies.
│ Proxy Server │◄────────────────────►│ Local (Docker) │
3
│ 100.98.32.42 │ │ │
4
│ :7890 │ │ │
5
└─────────────────┘ └──────────────────┘
In this case, both the host and containers can directly use the remote proxy address 100.98.32.42:7890. Docker containers (even with bridge network) route traffic through the host, which can access the VPN network normally.
Scenario 2: Proxy Running on the Host Locally
1
┌─────────────────────────────────────────┐
2
│ Host Machine │
3
│ ┌─────────────┐ ┌─────────────────┐ │
4
│ │ Proxy │ │ Docker Container│ │
5
│ │ 127.0.0.1 │◄───│ (bridge network)│ │
6
│ │ :7890 │ │ │ │
7
│ └─────────────┘ └─────────────────┘ │
8
└─────────────────────────────────────────┘
This scenario is more complex:
Services on the host can directly use 127.0.0.1:7890
But 127.0.0.1 inside a container refers to the container itself, not the host
Containers need to use 172.17.0.1:7890 (docker0 bridge address) to access the proxy on the host
When building images, pass proxy settings via the --build-arg parameter:
Terminal window
1
dockerbuild\
2
--build-arghttp_proxy=http://100.98.32.42:7890\
3
--build-arghttps_proxy=http://100.98.32.42:7890\
4
-timage_name.
NOTE
If your proxy is on a remote server (accessed via VPN), use the remote address directly. Container network traffic routes through the host, which can access proxies in the VPN network normally.
If the proxy is running locally on the host, use the docker0 bridge address:
Terminal window
1
dockerbuild\
2
--build-arghttp_proxy=http://172.17.0.1:7890\
3
--build-arghttps_proxy=http://172.17.0.1:7890\
4
-timage_name.
Or use --network=host to let the build process use the host network directly:
Configure ~/.docker/config.json to set proxy for all newly created containers:
Terminal window
1
vim~/.docker/config.json
1
{
2
"proxies": {
3
"default": {
4
"httpProxy": "http://100.98.32.42:7890",
5
"httpsProxy": "http://100.98.32.42:7890",
6
"noProxy": "localhost,127.0.0.1,.local"
7
}
8
}
9
}
IMPORTANT
This configuration only affects containers created by build and run. It does not affect docker pull. For pull, you still need to configure the systemd proxy as described above.
CAUTION
Once a container is created, proxy environment variables are embedded in it. Even if you modify or delete config.json later, existing containers will still use the proxy settings from creation time. To disable proxy, manually clear environment variables inside the container:
Docker’s config.json currently only supports HTTP/HTTPS/FTP protocols, not SOCKS5 directly. If you’re using Clash or similar proxies with mixed port support, the same port typically supports both HTTP and SOCKS5. Just use HTTP configuration.
The key is understanding where your proxy is deployed: use the remote address directly for remote proxies, and use 172.17.0.1 for local proxies when accessing from inside containers.
Docker Proxy Setup Guide - Mirror Acceleration and Proxy Configuration in China