Ravindra BagaleCourses & study guides Track your progress

Guides

Fix "Cannot connect to the Docker daemon. Is the docker daemon running?"

"Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?" means the docker command could not reach the Docker service (dockerd). On Linux and EC2, run sudo systemctl enable --now docker. If it does not start, sudo journalctl -u docker shows why, which is usually a broken /etc/docker/daemon.json or a full disk. On Windows and Mac, start Docker Desktop and wait for "Engine running".

Quick answer (Linux / EC2)

sudo systemctl status docker            # is it active (running)?
sudo systemctl enable --now docker      # start now + start at boot
sudo journalctl -u docker -n 50 --no-pager   # why it failed
docker run --rm hello-world             # test

A live example first

A student restarts an Amazon Linux 2023 EC2 instance after a lab and runs:

docker ps
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

Check the service:

sudo systemctl status docker
○ docker.service - Docker Application Container Engine
     Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; preset: disabled)
     Active: inactive (dead)

Two words matter here: inactive (it is not running now) and disabled (it will not start at boot). The student had run sudo systemctl start docker once, but never enable. After the reboot it was gone. The fix:

sudo systemctl enable --now docker
docker ps
CONTAINER ID   IMAGE   COMMAND   CREATED   STATUS   PORTS   NAMES

An empty table, with no error, means the daemon answered.

Why does Docker say the daemon is not running?

Docker client cannot reach the daemon The docker client sends a request to docker.sock. With dockerd stopped, nothing answers. Start and enable the service and it works. Docker client cannot reach the daemon docker psclientdocker.sockno answersystemctlstatus/startjournalctlwhy it failedRunningengine up you The docker command is only the client. dockerd must be running behind the socket

The docker command is a client. It needs the dockerd service running behind docker.sock.

Docker has two parts. The docker command you type is only a client. The real work is done by the daemon, dockerd, a background service. They talk through the socket file /var/run/docker.sock. If dockerd is stopped, crashed or never installed, the client knocks on the socket and nobody answers.

This is different from permission denied while trying to connect to the Docker daemon socket. In that case the daemon is running, but your user is not allowed to use the socket.

How do I fix it on Linux step by step?

  1. Run sudo systemctl status docker.
  2. If it says inactive or disabled, run sudo systemctl enable --now docker.
  3. If it says failed, run sudo journalctl -u docker -n 50 --no-pager.
  4. Read the last error line and match it in the table below.
  5. Fix the cause and run sudo systemctl restart docker.
  6. Run docker run --rm hello-world to prove it works.

Reading journalctl: the four usual causes

Log line Cause Fix
unable to configure the Docker daemon with file /​etc/​docker/​daemon.​json: invalid character '}' JSON syntax error Fix the file, check with python3 -​m json.​tool
no space left on device Disk full Free space, see the disk-full guide
failed to start daemon: pid file found, ensure docker is not running Stale PID file after a crash sudo rm /​var/​run/​docker.​pid then start
Unit docker.​service not found Docker is not installed Install it (Amazon Linux: sudo dnf install -​y docker)

The daemon.json trap

Many guides tell you to add a registry mirror or log options:

{
  "log-driver": "json-file",
  "log-opts": { "max-size": "10m", "max-file": "3" },
}

The comma after the last item makes it invalid JSON. Docker will refuse to start. Check before you restart:

sudo python3 -m json.tool /etc/docker/daemon.json

If it prints the file back, it is valid. If it prints Expecting property name, fix the line it names.

Fix it on Windows (Docker Desktop + WSL 2)

On Windows the error looks like this:

error during connect: ... open //./pipe/dockerDesktopLinuxEngine: The system cannot find the file specified.
  1. Start Docker Desktop from the Start menu.
  2. Wait until the bottom-left corner says Engine running.
  3. If it stays on "Starting", open PowerShell as admin.
  4. Run wsl --update.
  5. Run wsl --shutdown.
  6. Start Docker Desktop again.
  7. If it still fails, check that virtualisation is turned on in the BIOS (Task Manager → Performance → CPU → Virtualization: Enabled).

Fix it on macOS

  1. Open Docker Desktop from Applications.
  2. Wait for the whale icon in the menu bar to stop animating.
  3. If you use Colima or Rancher Desktop instead, run colima start.
  4. Run docker context ls and make sure the active context (with *) is the one that is running.

The docker context and DOCKER_HOST trap

If you once connected to a remote server, your client may still point there:

docker context ls
echo $DOCKER_HOST

Switch back with docker context use default and unset DOCKER_HOST.

Real example: Docker vs containerd in Kubernetes

Kubernetes removed "dockershim" in version 1.24 (May 2022). Since then, Amazon EKS, GKE and AKS nodes run containers with containerd, not the Docker daemon. So on a modern EKS node, docker ps may say "Cannot connect to the Docker daemon" even though every pod is running fine. That is expected. On those nodes use crictl ps or kubectl get pods. Your images built with Docker still run, because they follow the OCI image standard.

Mistakes students make

  1. Running start but not enable. It works until the next reboot.
  2. Running chmod 666 /var/run/docker.sock. That does not start a stopped daemon, and it lets every user on the machine control Docker (which is the same as root). Never do it.
  3. Editing daemon.json and restarting without checking. Always run json.tool first.
  4. Expecting Docker on Kubernetes nodes. Use crictl there.

Summary table

Where Check Fix
Linux / EC2 systemctl status docker systemctl enable --​now docker
Linux, failed journalctl -​u docker Fix daemon.json, disk or PID file
Windows Docker Desktop status Start it, wsl --update, wsl --shutdown
macOS Whale icon / colima status Start Docker Desktop or colima start
Any docker context ls docker context use default
EKS / GKE node containerd, not Docker crictl ps

Quick quiz: check what you learned

  1. What does the docker command talk to on Linux?

    1. dockerd through docker.sock
    2. The Docker Hub website
    3. The kubelet on each node
    4. The containerd image cache
    Show answer

    A. The CLI sends API calls to the daemon over the unix socket.

  2. Which command starts Docker now and at every boot?

    1. sudo systemctl enable --now docker
    2. sudo docker run --restart always
    3. sudo service docker logs -f now
    4. sudo chmod 666 docker.sock
    Show answer

    A. enable --now both starts the service and enables it at boot.

  3. Docker fails right after editing daemon.json. Check what?

    1. The JSON syntax in the file
    2. The Docker Hub login token
    3. The container memory limit
    4. The image tag in the Dockerfile
    Show answer

    A. One stray comma in daemon.json stops dockerd from starting.

  4. On Windows, what does Docker Desktop need to run Linux images?

    1. A working WSL 2 backend
    2. A running IIS web server
    3. The Hyper-V web console
    4. An Apache Tomcat service
    Show answer

    A. Docker Desktop runs its Linux engine inside WSL 2.

Learn it properly

This guide is the short path. These pages go deeper, with labs:

Frequently asked questions

What does "Is the docker daemon running?" mean?

The docker command is only a client. It talks to the dockerd service through /var/run/docker.sock. If dockerd is stopped, the client has nobody to talk to.

How do I start Docker on Ubuntu or Amazon Linux?

Run sudo systemctl enable --now docker, then sudo systemctl status docker and look for "active (running)".

Docker will not start after I edited daemon.json. Why?

A JSON syntax error, such as a trailing comma, stops dockerd from starting. Check it with python3 -m json.tool /etc/docker/daemon.json.

How do I fix it on Windows?

Start Docker Desktop and wait for "Engine running". If it fails, run wsl --update and wsl --shutdown in PowerShell, then start Docker Desktop again.

Is this the same as permission denied on docker.sock?

No. Permission denied means the daemon is running but your user cannot use the socket. "Is the daemon running" means nothing is listening.

Why does it work as root but not in my terminal?

Check DOCKER_HOST and docker context. A leftover context can point the client to a remote or old socket.