Configure Docker Proxy on Linux
When developing or deploying, Docker container images often need to be pulled from overseas registries, and poor network conditions can leave you stuck at docker pull. The most reliable approach is to configure an HTTP proxy for the Docker Daemon on the host, so all image pulls automatically go through the proxy.
Configure daemon.json
sudo mkdir -p /etc/docker
sudo nano /etc/docker/daemon.json
If the file doesn’t exist, create it and add the following:
{
"proxies": {
"http-proxy": "http://<host>:<port>",
"https-proxy": "http://<host>:<port>",
"no-proxy": "localhost,127.0.0.1,::1"
}
}
http-proxy/https-proxy: Point to an available proxy on your network.no-proxy: Addresses that should bypass the proxy, preventing local container traffic from taking unnecessary detours.
After saving, restart Docker to apply:
sudo systemctl daemon-reload
sudo systemctl restart docker
Verify the Proxy
Run docker info | grep -i proxy, you should see the HTTP/HTTPS Proxy fields.
Common Issues
- Proxy changed: Update
daemon.jsonand run the two systemctl commands again. - Private registry shouldn’t use proxy: Add the registry domain to
no-proxy.