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.
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.
First, verify whether the issue is Docker-specific or a general network problem:
# 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).
If you're behind a corporate proxy, Docker needs explicit proxy configuration:
# 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.confAdd your proxy settings:
[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:
sudo systemctl daemon-reload
sudo systemctl restart dockerVerify the settings are applied:
sudo systemctl show --property=Environment dockerDNS issues are a common cause. Configure Docker to use reliable public DNS servers:
# Edit Docker daemon configuration
sudo nano /etc/docker/daemon.jsonAdd or update the DNS configuration:
{
"dns": ["8.8.8.8", "8.8.4.4"]
}Restart Docker to apply:
sudo systemctl restart dockerFor Docker Desktop (Windows/Mac): Go to Settings > Docker Engine and add the DNS configuration to the JSON.
IPv6 can cause DNS resolution issues on some networks. Try disabling it:
# Add to /etc/sysctl.conf
sudo nano /etc/sysctl.confAdd these lines:
net.ipv6.conf.all.disable_ipv6=1
net.ipv6.conf.default.disable_ipv6=1
net.ipv6.conf.lo.disable_ipv6=1Apply the changes:
sudo sysctl --systemThen restart Docker:
sudo systemctl restart dockerVPN 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:
# Try pulling with host network mode (won't help for build/push)
docker pull --network host ubuntu:latestCorrupted Docker network configuration can cause connectivity issues:
# 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:
# 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 dockerLow disk space can cause network operations to hang and timeout:
# Check disk usage
df -h /var/lib/docker
# Check Docker's disk usage
docker system dfIf disk space is low, clean up:
# Remove unused containers, images, and build cache
docker system prune -a
# Include volumes if needed (WARNING: deletes data)
docker system prune -a --volumesSometimes the error is transient due to network congestion or rate limiting:
# 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
doneIf you're hitting Docker Hub rate limits, authenticate to increase your limit:
docker loginFree accounts get 200 pulls per 6 hours when authenticated vs. 100 pulls when anonymous.
Configure a Docker registry mirror to bypass network issues:
# Edit daemon.json
sudo nano /etc/docker/daemon.jsonAdd a mirror (example using Google's mirror for gcr.io images):
{
"registry-mirrors": ["https://mirror.gcr.io"]
}For corporate environments, your IT team may provide an internal registry mirror. Restart Docker after making changes:
sudo systemctl restart docker### 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:
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:
# Enable Docker daemon debug logging
sudo nano /etc/docker/daemon.json{
"debug": true
}Then check logs:
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
image operating system "linux" cannot be used on this platform
How to fix 'image operating system linux cannot be used on this platform' in Docker
manifest unknown: manifest unknown
How to fix 'manifest unknown' in Docker
cannot open '/etc/passwd': Permission denied
How to fix 'cannot open: Permission denied' in Docker
Error response from daemon: failed to create the ipvlan port
How to fix 'failed to create the ipvlan port' in Docker
toomanyrequests: Rate exceeded for anonymous users
How to fix 'Rate exceeded for anonymous users' in Docker Hub