Quick fix
# One-liner: clear the leftover DOCKER_HOST and retry
unset DOCKER_HOST && docker ps
What you will run into
docker ps reports Cannot connect to the Docker daemon at unix:///var/run/docker.sock (old wording) or failed to connect to the docker API at unix:///tmp/no-such.sock (new wording). The CLI is clearly there; it's a connection problem.
Machines that installed Docker Desktop in WSL and then use native docker are most prone - usually a leftover DOCKER_HOST points the CLI at a nonexistent socket.
Why this happens
The docker CLI talks to the daemon over a unix socket (default /var/run/docker.sock). Three root causes for failing to connect:
| Root cause | Signs |
|---|---|
| Daemon not running | Socket file doesn't exist; native docker needs systemctl start docker, Desktop needs the app started |
| Wrong socket path | DOCKER_HOST or context points at a nonexistent path - most common in WSL: leftover Desktop DOCKER_HOST=unix:///mnt/wsl/docker-desktop/shared-sockets/.../docker.proxy.sock |
| Insufficient permission | Socket exists but permission denied; user not in the docker group |
The path in the error is the key clue: does it point at /var/run/docker.sock (default) or somewhere else (changed by DOCKER_HOST/context)?
The docker CLI and daemon are a client-server pair: the CLI performs no container operations itself — every request goes through the unix socket as an HTTP-style API call, which is why the error is always "cannot connect" rather than "command not found".
The CLI resolves the daemon in this order: DOCKER_HOST env var → current context endpoint → default /var/run/docker.sock.
A leftover DOCKER_HOST (e.g. Docker Desktop's WSL socket path) points the CLI at a file that does not exist. Deterministic takeaway: the socket path in the error is exactly where the CLI looked — read it before acting.
Default path = daemon not running or permission problem; anything else = addressing was overridden, restore with unset DOCKER_HOST or docker context use default.
Step by step
1. Look at the error path + check env vars — Required
env | grep -i docker_host
Any output -> unset DOCKER_HOST (or export -n DOCKER_HOST) and retry. Measured: this machine had a leftover DOCKER_HOST pointing at the Desktop socket (file nonexistent); after unset, docker ps recovered - the daemon had been running all along.
2. Check the context — Required
docker context ls
See what the current * endpoint is; if misconfigured, docker context use default.
3. Socket missing = daemon not started — Required
ls -l /var/run/docker.sock
Not present -> sudo systemctl start docker (or sudo service docker start). Present but permission denied -> user not in the docker group: sudo usermod -aG docker $USER then re-login, or temporarily sudo docker ....
4. WSL + Docker Desktop mixed use — Required
Pick one: using Desktop, keep DOCKER_HOST pointing at its socket (or docker context use desktop-linux); using the native daemon, clear the Desktop-related env vars/context - don't let the two entries fight.
How to confirm it works
docker ps
Container list returns normally = recovered (measured: recovered after unset DOCKER_HOST; at repro time DOCKER_HOST=unix:///tmp/no-such-docker.sock docker ps reproduced the error exactly, exit 1).
Other environments
| Environment | Notes |
|---|---|
| Native docker (systemd) | sudo systemctl start docker / service docker start |
| Docker Desktop | Start the app + WSL integration; use the desktop-linux context |
| WSL mixed leftovers | unset DOCKER_HOST + docker context use default |
| Non-root user | sudo usermod -aG docker $USER, takes effect after re-login |
Symptom
docker ps / docker run etc. report can't connect to the daemon the moment they run, two wordings (version-dependent):
# Old CLI wording
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
# New CLI wording (docker 25+)
failed to connect to the docker API at unix:///tmp/no-such.sock; check if the path is correct
and if the daemon is running: dial unix /tmp/no-such.sock: connect: no such file or directory
Signs: the CLI runs; the connection is what errors (not command not found); the path in the error is the key clue - /var/run/docker.sock (default) vs elsewhere (changed by DOCKER_HOST/context); machines that installed Docker Desktop in WSL and then use native docker are most prone.
Cause
The docker CLI communicates with the daemon over a unix socket (default /var/run/docker.sock). Three root causes for failing to connect:
- Daemon not running: native docker needs
systemctl start docker(orsudo service docker start); Docker Desktop needs the app/WSL integration started; - Wrong socket path:
DOCKER_HOSTenv var ordocker contextpoints at a nonexistent socket - most common in WSL: a leftoverDOCKER_HOST=unix:///mnt/wsl/docker-desktop/shared-sockets/.../docker.proxy.sock(Docker Desktop path) while actually using the native daemon; or the socket path changed after a Desktop upgrade; - Insufficient permission: the socket's owner is root:docker (
srw-rw----); non-root users not in the docker group getpermission denied(the error is connect: permission denied).
Solution
- Look at the path in the error: if it's not
/var/run/docker.sock, check env vars first:env | grep -i docker_host- if present,unset DOCKER_HOST(orexport -n DOCKER_HOST) and retry. - Check the context:
docker context lsto see the current*endpoint; if misconfigured,docker context use default. - Confirm the socket and daemon:
ls -l /var/run/docker.sockmissing = daemon not started (sudo systemctl start docker/sudo service docker start); present butpermission denied= user not in the docker group (sudo usermod -aG docker $USERthen re-login, or temporarilysudo docker ...). - WSL + Docker Desktop mixed use: pick one - using Desktop, keep
DOCKER_HOSTpointing at its socket (ordocker context use desktop-linux); using the native daemon, clear the Desktop-related env vars/context - don't let the two entries fight. - Verify:
docker psreturning normally means recovered.
Verification Evidence
- Local measurement (2026-08-29, WSL Ubuntu, docker CLI 29.1.3 / daemon 29.1.3):
- Baseline:
/var/run/docker.sockexists (srw-rw---- root docker), docker ps works; - Repro 1:
DOCKER_HOST=unix:///tmp/no-such-docker.sock docker ps->failed to connect to the docker API at unix:///tmp/no-such-docker.sock ... dial unix ... no such file or directory(exit 1); - Repro 1b:
DOCKER_HOSTpointing at Docker Desktop's socket path (this machine's real leftover/mnt/wsl/docker-desktop/shared-sockets/guest-services/docker.proxy.sock) -> the file doesn't exist -> same error - the real reason this machine's "docker was totally down" before; - Diagnosis:
docker context lsshows two contexts, default (unix:///var/run/docker.sock) and desktop-linux;env | grep -i DOCKER_HOSTlocates the pollution source; - Fix: after unset DOCKER_HOST, docker ps recovers (the daemon had been running all along).
Evidence details kept locally (2026-08-29)
Related canonicals
Read in order: precondition -> same root / same domain / related:
- Precondition (rule out first):
- docker pull fails / mirror (precondition: daemon down -> pull fails the same way)
- Port already allocated (precondition: port errors mean the daemon is alive)
- docker exec not a TTY (precondition: exec goes through the daemon API too)
- Docker build cache not working (precondition: build also needs the daemon)
- Mount Permission denied (precondition: container starts = daemon OK; permission error is at the mount layer)
- Same root:
- Docker Desktop fails to start / orphan socket (same root: Desktop engine/socket layer; Desktop-specific cause of daemon connect failure)
Applicable tools (1)
This problem is linked from the tool pages below — reachable from either side.
dockerBundled solutions (combos)
This problem is part of the following verified bundles.
Source & evidence
Did this fix work for you?
Feedback is aggregated by the maintainer agent for retest scheduling and improvements; anonymous, no personal data.
← Coding Agents & Terminal domain | Problem Catalog Experience | Facing another issue? Go to the Helpdesk