Coding Agents & Terminal · recorded 2026-08-29 · applies to 1 tool(s) ✓ Verified

Problem: docker commands report Cannot connect to the Docker daemon at unix:///var/run/docker.sock / failed to connect to the docker API (can't reach the daemon) —— Trove problem library

Verified 2026-08-29Cannot connect to the Docker daemon — unset DOCKER_HOST first to rule out a stale env var, then confirm Docker Desktop is actually running.

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 causeSigns
Daemon not runningSocket file doesn't exist; native docker needs systemctl start docker, Desktop needs the app started
Wrong socket pathDOCKER_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 permissionSocket 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

EnvironmentNotes
Native docker (systemd)sudo systemctl start docker / service docker start
Docker DesktopStart the app + WSL integration; use the desktop-linux context
WSL mixed leftoversunset DOCKER_HOST + docker context use default
Non-root usersudo 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:

  1. Daemon not running: native docker needs systemctl start docker (or sudo service docker start); Docker Desktop needs the app/WSL integration started;
  2. Wrong socket path: DOCKER_HOST env var or docker context points at a nonexistent socket - most common in WSL: a leftover DOCKER_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;
  3. Insufficient permission: the socket's owner is root:docker (srw-rw----); non-root users not in the docker group get permission denied (the error is connect: permission denied).

Solution

  1. 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 (or export -n DOCKER_HOST) and retry.
  2. Check the context: docker context ls to see the current * endpoint; if misconfigured, docker context use default.
  3. Confirm the socket and daemon: ls -l /var/run/docker.sock missing = daemon not started (sudo systemctl start docker / 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: 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.
  5. Verify: docker ps returning 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.sock exists (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_HOST pointing 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 ls shows two contexts, default (unix:///var/run/docker.sock) and desktop-linux; env | grep -i DOCKER_HOST locates 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:

Applicable tools (1)

This problem is linked from the tool pages below — reachable from either side.

docker

Bundled solutions (combos)

This problem is part of the following verified bundles.

Source & evidence

Recorded Verified ✓ VerifiedApplies to 1 tool(s)
Entries contain locally measured or reviewable-source solutions; unmeasured items are explicitly labeled.

Source: https://github.com/docker/for-win/issues/14759

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