Ubuntu 17.10虚拟机Docker 18.04.0-ce代理环境下登录Docker Hub失败求助
Hey there, I’ve dealt with this exact proxy-related Docker login issue before, so let me break down the fixes that worked for me. That timeout error happens because Docker doesn’t automatically inherit your system’s proxy settings—you need to configure it explicitly for the Docker daemon to use your proxy.
Step 1: Create Docker Daemon Proxy Configuration
First, we’ll set up a dedicated config file for Docker’s proxy settings:
- Create the systemd service directory for Docker if it doesn’t exist:
sudo mkdir -p /etc/systemd/system/docker.service.d - Create a proxy config file (name it
http-proxy.conf):sudo nano /etc/systemd/system/docker.service.d/http-proxy.conf - Paste the following content, replacing
your-proxy-ipandportwith your actual proxy details. If your proxy requires authentication, add your credentials likeuser:password@before the proxy IP:
The[Service] Environment="HTTP_PROXY=http://your-proxy-ip:port/" Environment="HTTPS_PROXY=http://your-proxy-ip:port/" Environment="NO_PROXY=localhost,127.0.0.1,192.168.0.0/16"NO_PROXYline excludes local addresses and private networks from using the proxy—this prevents issues with local Docker containers and services.
Step 2: Apply the Configuration
After saving the file, reload the systemd daemon and restart Docker to make the changes take effect:
sudo systemctl daemon-reload sudo systemctl restart docker
Step 3: Verify the Proxy Setup
Check if Docker has picked up the proxy settings by running:
docker info
Scroll down to the Proxy Settings section—you should see your HTTP/HTTPS proxy listed here.
Step 4: Test Connectivity to Docker Hub
Before trying to log in again, test if the proxy can reach Docker Hub with curl:
curl -x http://your-proxy-ip:port https://registry-1.docker.io/v2/
A 401 Unauthorized response is normal here (it just means you haven’t authenticated yet). If you still get a timeout, double-check your proxy address, port, and credentials—there might be a network issue with your proxy server itself.
Final Step: Try Docker Login Again
Now run your login command again:
docker login -u <username> -p <cool password>
It should connect successfully to Docker Hub this time.
内容的提问来源于stack exchange,提问作者KALALEX

