How to fix net/http: request canceled while waiting for connection in Docker

DockerINTERMEDIATEMEDIUMUpdated Dec 6, 2025· 233 views

The 'request canceled while waiting for connection' error occurs when Docker cannot establish a network connection to a registry like Docker Hub. This is typically caused by network configuration issues, proxy settings, DNS problems, or firewall restrictions.

Quick fix

Fixes net/http: request canceled while waiting for connection

# Test if you can reach Docker Hub from your host
curl -v https://registry-1.docker.io/v2/

# Test DNS resolution
nslookup registry-1.docker.io

# If using GitHub Container Registry
curl -v https://ghcr.io/v2/
  1. Test network connectivity to Docker Hub
  2. Configure proxy settings for Docker daemon
  3. Configure DNS to use Google's public DNS
  4. Disable IPv6 if causing DNS instability
docker — error
# Test if you can reach Docker Hub from your host
curl -v https://registry-1.docker.io/v2/
# Test DNS resolution
nslookup registry-1.docker.io
# If using GitHub Container Registry
curl -v https://ghcr.io/v2/
net/http: request canceled while waiting for connection

What this error means

The "net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)" error indicates that Docker's HTTP client timed out while trying to establish a connection to a remote server, most commonly a container registry like Docker Hub (registry-1.docker.io) or GitHub Container Registry (ghcr.io). When you run commands like `docker pull`, `docker push`, or `docker build` (which pulls base images), Docker needs to connect to these registries over the internet. This error means the connection attempt took too long and was canceled, usually because: 1. The request never reached the destination server 2. A response was never received 3. The connection was blocked by a firewall or proxy Unlike a "connection refused" error (where the server actively rejects the connection), this timeout error suggests the packets are being dropped or the network path is unreachable. This makes it one of the more frustrating Docker errors to diagnose because it could stem from many different network layers.

Typical symptoms

  • docker pull commands fail with 'Client.Timeout exceeded while awaiting headers'
  • docker build fails at FROM instruction when pulling base images
  • docker push times out when uploading images to a registry
  • docker login hangs and eventually times out
  • Error occurs consistently behind corporate networks or VPNs
  • Commands work intermittently - sometimes succeeding on retry
  • Error mentions registry-1.docker.io, ghcr.io, or other registry URLs
  • curl or wget to the same registry URL works from the host

Common causes

  1. Corporate proxy not configured for Docker daemon
  2. DNS resolution issues (especially with IPv6)
  3. VPN connection blocking or interfering with Docker traffic
  4. Firewall rules blocking outbound HTTPS connections from Docker
  5. Docker Hub rate limiting (for unauthenticated pulls)
  6. Insufficient disk space causing network operations to stall
  7. Network adapter or Docker network configuration conflicts
  8. ISP or regional network issues blocking container registry access

How to fix "net/http: request canceled while waiting for connection"

1Test network connectivity to Docker Hub

First, verify whether the issue is Docker-specific or a general network problem:

bash
# Test if you can reach Docker Hub from your host
curl -v https://registry-1.docker.io/v2/

# Test DNS resolution
nslookup registry-1.docker.io

# If using GitHub Container Registry
curl -v https://ghcr.io/v2/

If curl works but Docker doesn't, the issue is likely with Docker's network configuration (proxy, DNS, or firewall settings specific to Docker).

2Configure proxy settings for Docker daemon

If you're behind a corporate proxy, Docker needs explicit proxy configuration:

bash
# Create the systemd drop-in directory
sudo mkdir -p /etc/systemd/system/docker.service.d

# Create the proxy configuration file
sudo nano /etc/systemd/system/docker.service.d/http-proxy.conf

Add your proxy settings:

ini
[Service]
Environment="HTTP_PROXY=http://proxy.example.com:8080"
Environment="HTTPS_PROXY=http://proxy.example.com:8080"
Environment="NO_PROXY=localhost,127.0.0.1,.example.com"

Then reload and restart Docker:

bash
sudo systemctl daemon-reload
sudo systemctl restart docker

Verify the settings are applied:

bash
sudo systemctl show --property=Environment docker
3Configure DNS to use Google's public DNS

DNS issues are a common cause. Configure Docker to use reliable public DNS servers:

bash
# Edit Docker daemon configuration
sudo nano /etc/docker/daemon.json

Add or update the DNS configuration:

json
{
  "dns": ["8.8.8.8", "8.8.4.4"]
}

Restart Docker to apply:

bash
sudo systemctl restart docker

For Docker Desktop (Windows/Mac): Go to Settings > Docker Engine and add the DNS configuration to the JSON.

4Disable IPv6 if causing DNS instability

IPv6 can cause DNS resolution issues on some networks. Try disabling it:

bash
# Add to /etc/sysctl.conf
sudo nano /etc/sysctl.conf

Add these lines:

bash
net.ipv6.conf.all.disable_ipv6=1
net.ipv6.conf.default.disable_ipv6=1
net.ipv6.conf.lo.disable_ipv6=1

Apply the changes:

bash
sudo sysctl --system

Then restart Docker:

bash
sudo systemctl restart docker
5Check and disconnect VPN if interfering

VPN connections often route Docker traffic incorrectly:

1. Temporarily disconnect your VPN and try the Docker command again
2. If it works without VPN, you need to configure VPN split tunneling

For most VPNs, you can exclude Docker traffic by adding these routes to your VPN's split tunnel configuration:
- registry-1.docker.io
- auth.docker.io
- production.cloudflare.docker.com

Alternatively, configure Docker to use the host network for pulls:

bash
# Try pulling with host network mode (won't help for build/push)
docker pull --network host ubuntu:latest
6Clean up Docker networks

Corrupted Docker network configuration can cause connectivity issues:

bash
# Remove unused networks
docker network prune

# List all networks
docker network ls

# If you see duplicate or stale networks, remove them
docker network rm <network_name>

In severe cases, reset Docker's network completely:

bash
# Stop Docker
sudo systemctl stop docker

# Remove network configuration (safe - Docker will recreate it)
sudo rm -rf /var/lib/docker/network

# Restart Docker
sudo systemctl start docker
7Check disk space

Low disk space can cause network operations to hang and timeout:

bash
# Check disk usage
df -h /var/lib/docker

# Check Docker's disk usage
docker system df

If disk space is low, clean up:

bash
# Remove unused containers, images, and build cache
docker system prune -a

# Include volumes if needed (WARNING: deletes data)
docker system prune -a --volumes
8Retry the command

Sometimes the error is transient due to network congestion or rate limiting:

bash
# Simply retry the pull command
docker pull ubuntu:latest

# Or use a script for automated retry
for i in {1..5}; do
  docker pull ubuntu:latest && break
  echo "Attempt $i failed, retrying in 10 seconds..."
  sleep 10
done

If you're hitting Docker Hub rate limits, authenticate to increase your limit:

bash
docker login

Free accounts get 200 pulls per 6 hours when authenticated vs. 100 pulls when anonymous.

9Use a registry mirror

Configure a Docker registry mirror to bypass network issues:

bash
# Edit daemon.json
sudo nano /etc/docker/daemon.json

Add a mirror (example using Google's mirror for gcr.io images):

json
{
  "registry-mirrors": ["https://mirror.gcr.io"]
}

For corporate environments, your IT team may provide an internal registry mirror. Restart Docker after making changes:

bash
sudo systemctl restart docker

Advanced notes

### Understanding the Timeout

The default timeout for Docker registry operations is typically 30 seconds. When this error occurs, Docker has waited the full timeout period without receiving a response. The full error message often includes:

bash
Get "https://registry-1.docker.io/v2/": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)

### Docker Desktop Specific Issues

Windows: The virtual network adapter "vEthernet (DockerNAT)" or "vEthernet (WSL)" may need its DNS settings configured:
1. Open Network Connections (ncpa.cpl)
2. Find the Docker virtual adapter
3. Set DNS to 8.8.8.8 and 8.8.4.4

Mac: Docker Desktop for Mac uses a lightweight VM. Try resetting it via Docker Desktop > Troubleshoot > Reset to factory defaults (back up your images first!).

### CI/CD Environments

In CI/CD pipelines (GitHub Actions, GitLab CI, etc.), this error often indicates:
- Rate limiting from too many pulls
- Intermittent network issues in the cloud provider
- Registry outages

Solutions:
1. Use authenticated pulls to increase rate limits
2. Cache base images in your own registry
3. Add retry logic to your pipeline
4. Use registry mirrors provided by your CI platform

### Debugging Network Issues

For advanced debugging:

bash
# Enable Docker daemon debug logging
sudo nano /etc/docker/daemon.json
json
{
  "debug": true
}

Then check logs:

bash
sudo journalctl -u docker -f

### Alternative Registries

If Docker Hub is consistently problematic, consider:
- GitHub Container Registry (ghcr.io) - Good for open source projects
- Amazon ECR Public - Fast in AWS regions
- Google Container Registry (gcr.io) - Fast in GCP regions
- Quay.io - Alternative to Docker Hub

Frequently asked questions

What does "net/http: request canceled while waiting for connection" mean?
io). When you run commands like docker pull, docker push, or docker build (which pulls base images), Docker needs to connect to these registries over the internet. This error means the connection attempt took too long and was canceled, usually because: 1.
How do I fix "net/http: request canceled while waiting for connection"?
The 'request canceled while waiting for connection' error occurs when Docker cannot establish a network connection to a registry like Docker Hub. This is typically caused by network configuration issues, proxy settings, DNS problems, or firewall restrictions.
What causes "net/http: request canceled while waiting for connection"?
Corporate proxy not configured for Docker daemon DNS resolution issues (especially with IPv6) VPN connection blocking or interfering with Docker traffic
Is the "net/http: request canceled while waiting for connection" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading