How to fix context deadline exceeded in Docker
The 'context deadline exceeded' error occurs when a Docker operation fails to complete within the allotted timeout period. This typically indicates network connectivity issues, DNS resolution failures, slow registry responses, or Docker daemon problems.
Quick fix
Fixes context deadline exceeded
# Test connectivity to Docker Hub
curl -I https://registry-1.docker.io/v2/
# Test DNS resolution
nslookup registry-1.docker.io
# Check for latency issues
ping -c 5 registry-1.docker.io- Verify network connectivity to Docker registry
- Configure DNS settings
- Increase timeout for Docker Compose
- Manually pull images before deployment
# Test connectivity to Docker Hubcurl -I https://registry-1.docker.io/v2/# Test DNS resolutionnslookup registry-1.docker.io# Check for latency issuesping -c 5 registry-1.docker.iocontext deadline exceeded
What this error means
The "context deadline exceeded" error is a timeout message originating from Go's context package, which Docker uses internally. When you see this error, it means that a Docker API request or network operation took longer than the configured timeout and was cancelled. This error commonly appears during operations like pulling images from a registry, pushing images, or when the Docker daemon fails to respond in time. The "deadline" refers to the maximum time allowed for an operation to complete, and "exceeded" means that time limit was reached before the operation finished. The error is often a symptom of underlying network or infrastructure issues rather than a problem with Docker itself. It frequently indicates connectivity problems between your Docker client/daemon and container registries, DNS resolution failures, or resource constraints on the host system.
Typical symptoms
- docker pull fails with 'Error response from daemon: Get https://registry-1.docker.io/v2/: context deadline exceeded'
- Docker Compose fails to start services with timeout errors
- Kubernetes pods stuck in ImagePullBackOff with context deadline exceeded
- Docker Swarm nodes fail to join or communicate
- docker build hangs and eventually times out when fetching base images
- CI/CD pipelines fail intermittently with this error
- Docker API operations become unresponsive
- Containers fail to attach to overlay networks with deadline errors
Common causes
- Slow or unstable network connection to Docker registries
- DNS resolution failures or misconfiguration (especially with systemd-resolved)
- Firewall or proxy blocking connections to registry endpoints
- Docker daemon is unresponsive or under heavy load
- Large images exceeding default timeout during slow downloads
- Docker Swarm node in drain state preventing network resource allocation
- Corporate VPN or proxy interfering with Docker network traffic
- Registry server experiencing high latency or outages
- Mismatched Docker Engine versions in a Swarm cluster
- Required ports blocked for Docker Swarm communication
How to fix "context deadline exceeded"
First, check if you can reach the Docker registry from your host:
# Test connectivity to Docker Hub
curl -I https://registry-1.docker.io/v2/
# Test DNS resolution
nslookup registry-1.docker.io
# Check for latency issues
ping -c 5 registry-1.docker.ioIf these commands fail or show high latency, you have a network connectivity issue that needs to be resolved first.
DNS misconfiguration is one of the most common causes. On Linux systems using systemd-resolved, Docker may not be able to use the localhost DNS resolver:
# Check current DNS configuration
cat /etc/resolv.confIf you see nameserver 127.0.0.53, configure Docker to use public DNS:
sudo nano /etc/docker/daemon.jsonAdd or update:
{
"dns": ["8.8.8.8", "8.8.4.4", "1.1.1.1"]
}Then restart Docker:
sudo systemctl restart dockerIf using Docker Compose, increase the HTTP timeout:
# Set environment variable before running compose
export COMPOSE_HTTP_TIMEOUT=200
# Or inline with the command
COMPOSE_HTTP_TIMEOUT=200 docker-compose upFor persistent configuration, add to your shell profile (~/.bashrc or ~/.zshrc):
export COMPOSE_HTTP_TIMEOUT=200For Kubernetes or orchestration platforms with internal timeouts, pre-pull large images manually:
# Pull the image directly (no orchestration timeout)
docker pull mcr.microsoft.com/mssql/server:2019-latest
# Verify it's cached locally
docker images | grep mssqlOnce cached locally, subsequent deployments will use the local image instead of timing out during download.
If using Docker Swarm, verify nodes are not in drain state:
# Check node availability
docker node ls
# Inspect specific node status
docker node inspect --format '{{.Spec.Availability}}' <node-name>If a node shows "drain", it cannot receive overlay network resources, causing deadline errors:
# Activate the node
docker node update --availability active <node-name>Docker Swarm requires specific ports for communication. Ensure these are open:
- TCP 2377: Cluster management communications
- TCP/UDP 7946: Node communication
- UDP 4789: Overlay network traffic
Check firewall rules:
# For firewalld
sudo firewall-cmd --list-all
# For ufw
sudo ufw status
# Open required ports (firewalld example)
sudo firewall-cmd --permanent --add-port=2377/tcp
sudo firewall-cmd --permanent --add-port=7946/tcp
sudo firewall-cmd --permanent --add-port=7946/udp
sudo firewall-cmd --permanent --add-port=4789/udp
sudo firewall-cmd --reloadVerify the Docker daemon is responsive:
# Check Docker service status
sudo systemctl status docker
# Test daemon responsiveness
docker info
# View daemon logs for errors
sudo journalctl -u docker -n 50 --no-pagerIf the daemon is unresponsive, restart it:
sudo systemctl restart dockerFor persistent issues, enable debug mode in /etc/docker/daemon.json:
{
"debug": true
}In Swarm clusters, mismatched versions can cause timeout issues:
# Check versions across all nodes
docker node ls --format '{{.Hostname}}: {{.EngineVersion}}'
# Or on each node individually
docker version --format '{{.Server.Version}}'If versions differ significantly, upgrade nodes to a consistent version:
# On Debian/Ubuntu
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.ioAdvanced notes
GitLab Runner Configuration: If using GitLab CI with Kubernetes executor, increase the poll_timeout in your runner's config.toml file to handle slower cluster API responses.
Azure Container Registry: For ACR-specific deadline issues, verify your registry's sign-in server DNS resolves correctly with nslookup <registry-name>.azurecr.io. Private endpoints may require specific DNS configuration.
Proxy Environments: In corporate environments, ensure Docker is configured to use your proxy:
{
"proxies": {
"default": {
"httpProxy": "http://proxy.example.com:8080",
"httpsProxy": "http://proxy.example.com:8080",
"noProxy": "localhost,127.0.0.1"
}
}
}BuildKit Timeouts: For docker build timeouts with BuildKit, you may see "failed to solve: DeadlineExceeded". This often relates to slow base image pulls. Consider using a local registry mirror or pre-caching base images.
Rootless Docker: In rootless mode, networking uses slirp4netns which can have different timeout characteristics. Consider adjusting slirp4netns settings if experiencing consistent timeouts.
WSL2 Considerations: On Windows with WSL2, network issues can arise from DNS configuration conflicts between Windows and the WSL2 VM. Try adding your Windows host DNS to the WSL2 resolv.conf.
Frequently asked questions
- What does "context deadline exceeded" mean?
- The "context deadline exceeded" error is a timeout message originating from Go's context package, which Docker uses internally. When you see this error, it means that a Docker API request or network operation took longer than the configured timeout and was cancelled. This error commonly appears during operations like pulling images from a registry, pushing images, or when the Docker daemon fails to respond in time.
- How do I fix "context deadline exceeded"?
- The 'context deadline exceeded' error occurs when a Docker operation fails to complete within the allotted timeout period. This typically indicates network connectivity issues, DNS resolution failures, slow registry responses, or Docker daemon problems.
- What causes "context deadline exceeded"?
- Slow or unstable network connection to Docker registries DNS resolution failures or misconfiguration (especially with systemd-resolved) Firewall or proxy blocking connections to registry endpoints
- Is the "context deadline exceeded" error serious?
- It is a medium-severity error โ more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- ๐Docker Official Documentation
- ๐100 Common Docker Errors & Solutions(Official Docs)
- ๐ฌError on context deadline with docker - Stack Overflow(Stack Overflow)
- ๐ฌDocker Community Forums - Context deadline exceeded(Stack Overflow)
- ๐ฌDocker Forums - Registry context deadline exceeded(Stack Overflow)
- ๐Microsoft - Azure Container Registry deadline errors(Official Docs)
- ๐LabEx - Troubleshooting Docker API Context Deadline Exceeded(Official Docs)
- ๐Bobcares - Docker Context Deadline Exceeded Tips(Official Docs)
- ๐
- ๐ฌServer Fault - Kubernetes pod context deadline exceeded(Stack Overflow)