How to fix error during connect: Post http://%2Fvar%2Frun%2Fdocker.sock: read unix: connection reset by peer in Docker

DockerINTERMEDIATEMEDIUMUpdated Dec 6, 2025ยท 269 views

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
  1. Check if Docker daemon is running
  2. Check Docker daemon logs for errors
  3. Check available disk space
  4. Check system memory usage
docker โ€” error
# Check daemon status
sudo systemctl status docker
# Or on systems without systemd
sudo service docker status
error 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

  1. Docker daemon crashed or was killed by the OOM killer due to memory exhaustion
  2. Disk space exhausted on the Docker storage directory (/var/lib/docker)
  3. Docker daemon is overloaded with too many concurrent operations
  4. Corrupted Docker daemon state or socket file
  5. System resource limits (ulimits) are too restrictive
  6. Network issues when using Docker over SSH or TCP
  7. Docker daemon configuration issues or incompatible settings
  8. 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"

1Check if Docker daemon is running

First, verify the Docker daemon's current status:

bash
# Check daemon status
sudo systemctl status docker

# Or on systems without systemd
sudo service docker status

If the daemon is stopped or failed, start it:

bash
sudo systemctl start docker
2Check Docker daemon logs for errors

Review the daemon logs to understand why the connection was reset:

bash
# 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.log

Look for error messages about memory, disk space, or crashes. Common patterns include "out of memory", "no space left on device", or segmentation faults.

3Check available disk space

Low disk space is one of the most common causes. Check your Docker storage:

bash
# Check disk usage on the Docker directory
df -h /var/lib/docker

# Check Docker's disk usage
docker system df

If disk space is low, clean up unused resources:

bash
# 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 --volumes
4Check system memory usage

Memory exhaustion can cause the OOM killer to terminate the Docker daemon:

bash
# Check current memory usage
free -h

# Check if Docker was OOM killed
dmesg | grep -i "killed process" | grep -i docker

If the daemon was OOM killed, consider:
- Reducing the number of concurrent containers
- Adding swap space
- Increasing system memory
- Setting memory limits on containers

5Restart the Docker daemon

A clean restart often resolves transient issues:

bash
# Stop and start Docker
sudo systemctl restart docker

# Verify it's running
sudo systemctl status docker

After restarting, test with a simple command:

bash
docker ps
docker info
6Check and fix socket permissions

Ensure the Docker socket exists and has correct permissions:

bash
# Check socket exists
ls -la /var/run/docker.sock

# Should show: srw-rw---- 1 root docker

If the socket is missing or has wrong permissions:

bash
# 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 effect
7Increase system resource limits

If the daemon is hitting resource limits, increase them:

bash
# Check current limits
ulimit -a

# Edit Docker service limits
sudo systemctl edit docker

Add these lines:

ini
[Service]
LimitNOFILE=1048576
LimitNPROC=infinity
LimitCORE=infinity

Then reload and restart:

bash
sudo systemctl daemon-reload
sudo systemctl restart docker
8Reset Docker to a clean state (last resort)

If nothing else works, you can reset Docker completely:

bash
# 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 docker

Warning: 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:

bash
# Debian/Ubuntu
sudo apt-get install -y dbus-user-session

# Fedora/RHEL
sudo dnf install -y dbus-daemon

Then 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