How to Fix Docker Timeout Error on AWS EC2


Troubleshooting Guide: Fixing “Docker Timeout Error” on AWS EC2

1. The Root Cause: On AWS EC2, “Docker Timeout Errors” frequently stem from variable network performance, particularly on smaller instances or under heavy load. This can cause Docker’s default, often conservative, timeouts for registry interactions (image pulls/pushes) or build operations to be exceeded, especially when dealing with large images or distant registries.

2. Quick Fix (CLI): Adjust Docker daemon configuration to improve network resilience and concurrency.

# SSH into your EC2 instance

# 1. Create or edit the Docker daemon configuration file
sudo mkdir -p /etc/docker
sudo vi /etc/docker/daemon.json

2. Add or modify the following JSON content: This configuration sets reliable public DNS servers and increases the number of concurrent downloads/uploads, which significantly improves resilience against network latency and throughput issues.

{
  "dns": ["8.8.8.8", "1.1.1.1"],
  "max-concurrent-downloads": 10,
  "max-concurrent-uploads": 10
}
# 3. Save the file (if using vi, press ESC, then :wq)

# 4. Reload the Docker daemon to apply changes
sudo systemctl daemon-reload
sudo systemctl restart docker

3. Configuration Check: Verify the content of /etc/docker/daemon.json. It should contain entries similar to the following:

{
  "dns": ["8.8.8.8", "1.1.1.1"],
  "max-concurrent-downloads": 10,
  "max-concurrent-uploads": 10
}

These settings configure Docker to use robust DNS servers and increase the number of simultaneous layer downloads/uploads, directly mitigating common network-related timeouts.

4. Verification: Confirm that the Docker daemon has loaded the new configuration.

docker info | grep -E "DNS Server|Concurrent"

You should see output similar to:

 DNS Server: 8.8.8.8
 DNS Server: 1.1.1.1
 Concurrent Downloads: 10
 Concurrent Uploads: 10

This indicates the new settings are active. Now, re-attempt the Docker operation that previously timed out.