The 'connection reset by peer' error occurs when the Docker daemon unexpectedly closes the connection to the Docker socket. This typically indicates daemon crashes, resource exhaustion, or socket communication issues.
The "connection reset by peer" error in Docker indicates that the Docker daemon abruptly terminated the connection while your Docker client was trying to communicate with it through the Unix socket (/var/run/docker.sock). When you run any Docker command, the Docker CLI sends a request to the Docker daemon via this socket. If the daemon crashes, runs out of resources, or the socket connection is interrupted, the operating system returns a "connection reset by peer" error - meaning the other end (the daemon) forcibly closed the connection. This error is particularly frustrating because it can appear seemingly at random, often during resource-intensive operations like building images, pulling large images, or when the host system is under memory pressure. Unlike a simple "daemon not running" error, this indicates the daemon was running but encountered a problem mid-communication.
First, verify the Docker daemon's current status:
# Check daemon status
sudo systemctl status docker
# Or on systems without systemd
sudo service docker statusIf the daemon is stopped or failed, start it:
sudo systemctl start dockerReview the daemon logs to understand why the connection was reset:
# View recent Docker daemon logs
sudo journalctl -u docker --since "10 minutes ago"
# Or check the log file directly
sudo tail -100 /var/log/docker.logLook for error messages about memory, disk space, or crashes. Common patterns include "out of memory", "no space left on device", or segmentation faults.
Low disk space is one of the most common causes. Check your Docker storage:
# Check disk usage on the Docker directory
df -h /var/lib/docker
# Check Docker's disk usage
docker system dfIf disk space is low, clean up unused resources:
# Remove unused containers, networks, images, and build cache
docker system prune -a
# Also remove unused volumes (be careful - this deletes data)
docker system prune -a --volumesMemory exhaustion can cause the OOM killer to terminate the Docker daemon:
# Check current memory usage
free -h
# Check if Docker was OOM killed
dmesg | grep -i "killed process" | grep -i dockerIf the daemon was OOM killed, consider:
- Reducing the number of concurrent containers
- Adding swap space
- Increasing system memory
- Setting memory limits on containers
A clean restart often resolves transient issues:
# Stop and start Docker
sudo systemctl restart docker
# Verify it's running
sudo systemctl status dockerAfter restarting, test with a simple command:
docker ps
docker infoEnsure the Docker socket exists and has correct permissions:
# Check socket exists
ls -la /var/run/docker.sock
# Should show: srw-rw---- 1 root dockerIf the socket is missing or has wrong permissions:
# Restart Docker to recreate the socket
sudo systemctl restart docker
# Ensure your user is in the docker group
sudo usermod -aG docker $USER
# Log out and back in for group changes to take effectIf the daemon is hitting resource limits, increase them:
# Check current limits
ulimit -a
# Edit Docker service limits
sudo systemctl edit dockerAdd these lines:
[Service]
LimitNOFILE=1048576
LimitNPROC=infinity
LimitCORE=infinityThen reload and restart:
sudo systemctl daemon-reload
sudo systemctl restart dockerIf nothing else works, you can reset Docker completely:
# Stop Docker
sudo systemctl stop docker
# Back up any important data first!
# Remove Docker's state (WARNING: deletes all containers, images, volumes)
sudo rm -rf /var/lib/docker
# Restart Docker
sudo systemctl start dockerWarning: This will delete all Docker data including containers, images, and volumes. Only use as a last resort after backing up important data.
### Understanding the Socket Communication
The Docker socket at /var/run/docker.sock is a Unix domain socket that allows the Docker client to communicate with the Docker daemon. When you see the URL-encoded path %2Fvar%2Frun%2Fdocker.sock in the error, this is simply the encoded form of /var/run/docker.sock.
### Rootless Docker Considerations
If you're running rootless Docker, the socket path is different (typically $XDG_RUNTIME_DIR/docker.sock). Connection reset errors in rootless mode may also require installing dbus-user-session:
# Debian/Ubuntu
sudo apt-get install -y dbus-user-session
# Fedora/RHEL
sudo dnf install -y dbus-daemonThen log out and back in.
### Docker Over SSH/TCP
If you're connecting to a remote Docker daemon and experiencing this error, check:
- Network stability between client and host
- SSH connection timeouts
- Firewall rules blocking the connection
- TLS certificate validity if using TCP with TLS
### Storage Driver Issues
Some storage drivers are more prone to corruption that can cause daemon instability:
- overlay2 (recommended) is generally the most stable
- devicemapper can have issues with thin pool exhaustion
- aufs is deprecated and may cause issues
Check your storage driver with docker info | grep "Storage Driver".
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