Docker代理服务器配置求助:运行hello-world时连接镜像仓库超时
Got it, let's fix this proxy issue so you can pull the hello-world image without those timeout errors. The problem is Docker isn't using your network proxy to reach Docker Hub, so we need to configure Docker to route its requests through your proxy server. Here's how to do it based on your operating system:
Linux Systems
- First, create the directory for Docker service configuration overrides:
sudo mkdir -p /etc/systemd/system/docker.service.d - Create a proxy configuration file named
http-proxy.confwith your proxy details:
Replace[Service] Environment="HTTP_PROXY=http://your-proxy-address:port/" Environment="HTTPS_PROXY=http://your-proxy-address:port/" Environment="NO_PROXY=localhost,127.0.0.1,192.168.0.0/16"your-proxy-address:portwith your actual proxy server details. TheNO_PROXYline lists addresses that don't need to go through the proxy (adjust this to include any local or private registry addresses you use). - Reload the systemd daemon to pick up the new configuration:
sudo systemctl daemon-reload - Restart Docker to apply the proxy settings:
sudo systemctl restart docker - Verify the proxy is set correctly by running:
You should see your proxy addresses listed here.docker info | grep -A 2 "Proxy"
Windows Systems (Docker Desktop)
- Open Docker Desktop and click the gear icon (Settings) in the top-right corner.
- Navigate to Resources → Proxies.
- Select Manual proxy configuration.
- Enter your proxy details in the
HTTP ProxyandHTTPS Proxyfields (format:http://proxy-address:port). - Add any local or internal addresses to the
No proxyfield (e.g.,localhost,127.0.0.1). - Click Apply & Restart to save the settings and restart Docker.
macOS Systems (Docker Desktop)
- Click the Docker icon in your top menu bar and select Preferences.
- Go to Resources → Proxies.
- Choose Manual proxy configuration.
- Input your HTTP and HTTPS proxy addresses in the respective fields.
- Add excluded hosts (local addresses, private registries) to the
Exclude hostsbox. - Click Apply & Restart to activate the proxy settings.
Bonus: Docker Compose Proxy Settings
If you need proxy settings specifically for Docker Compose (though the global Docker config should cover this), you can create a .env file in your Compose project directory with:
HTTP_PROXY=http://your-proxy-address:port/ HTTPS_PROXY=http://your-proxy-address:port/ NO_PROXY=localhost,127.0.0.1
Compose will automatically use these environment variables when running services.
Once you've completed the configuration, test it out by running:
docker run hello-world
This should now successfully pull the image and run the test container.
内容的提问来源于stack exchange,提问作者Saqib Jutt

