How to fix error during connect: Post http://%2Fvar%2Frun%2Fdocker.sock: read unix: connection reset by peer in Docker
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.
Quick fix
Fixes error during connect: Post http://%2Fvar%2Frun%2Fdocker.sock: read unix: connection reset by peer
# Check daemon status
sudo systemctl status docker
# Or on systems without systemd
sudo service docker status- Check if Docker daemon is running
- Check Docker daemon logs for errors
- Check available disk space
- Check system memory usage
# Check daemon statussudo systemctl status docker# Or on systems without systemdsudo service docker statuserror during connect: Post http://%2Fvar%2Frun%2Fdocker.sock: read unix: connection reset by peer
What this error means
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.
Typical symptoms
- Docker commands fail intermittently with 'connection reset by peer' error
- Commands work after restarting Docker daemon but fail again under load
- Error appears during docker build, docker pull, or docker push operations
- Host system shows high memory or CPU usage when error occurs
- Docker daemon logs show errors or restarts around the same time
- Error occurs more frequently when disk space is low
Common causes
- Docker daemon crashed or was killed by the OOM killer due to memory exhaustion
- Disk space exhausted on the Docker storage directory (/var/lib/docker)
- Docker daemon is overloaded with too many concurrent operations
- Corrupted Docker daemon state or socket file
- System resource limits (ulimits) are too restrictive
- Network issues when using Docker over SSH or TCP
- Docker daemon configuration issues or incompatible settings
- Hardware issues affecting the Docker storage backend
How to fix "error during connect: Post http://%2Fvar%2Frun%2Fdocker.sock: read unix: connection reset by peer"
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.
Advanced notes
### 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".
Frequently asked questions
- What does "error during connect: Post http://%2Fvar%2Frun%2Fdocker.sock: read uni" mean?
- 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.
- How do I fix "error during connect: Post http://%2Fvar%2Frun%2Fdocker.sock: read uni"?
- 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.
- What causes "error during connect: Post http://%2Fvar%2Frun%2Fdocker.sock: read uni"?
- Docker daemon crashed or was killed by the OOM killer due to memory exhaustion Disk space exhausted on the Docker storage directory (/var/lib/docker) Docker daemon is overloaded with too many concurrent operations
- Is the "error during connect: Post http://%2Fvar%2Frun%2Fdocker.sock: read uni" 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
- ๐
- ๐Troubleshooting the Docker daemon - Docker Docs(Official Docs)
- ๐Rootless Docker Troubleshooting - Docker Docs(Official Docs)
- ๐ฌHow to fix read: connection reset by peer in docker?(Stack Overflow)
- ๐ฌdocker-py: Connection reset by peer - Stack Overflow(Stack Overflow)
- ๐ฌDocker Pull - connection reset by peer - Stack Overflow(Stack Overflow)