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?
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?
- Run
sudo systemctl status docker. - If it says inactive or disabled, run
sudo systemctl enable --now docker. - If it says failed, run
sudo journalctl -u docker -n 50 --no-pager. - Read the last error line and match it in the table below.
- Fix the cause and run
sudo systemctl restart docker. - Run
docker run --rm hello-worldto 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.
- Start Docker Desktop from the Start menu.
- Wait until the bottom-left corner says Engine running.
- If it stays on "Starting", open PowerShell as admin.
- Run
wsl --update. - Run
wsl --shutdown. - Start Docker Desktop again.
- If it still fails, check that virtualisation is turned on in the BIOS (Task Manager → Performance → CPU → Virtualization: Enabled).
Fix it on macOS
- Open Docker Desktop from Applications.
- Wait for the whale icon in the menu bar to stop animating.
- If you use Colima or Rancher Desktop instead, run
colima start. - Run
docker context lsand 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
- Running
startbut notenable. It works until the next reboot. - 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. - Editing daemon.json and restarting without checking. Always run
json.toolfirst. - Expecting Docker on Kubernetes nodes. Use
crictlthere.
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
What does the docker command talk to on Linux?
- dockerd through docker.sock
- The Docker Hub website
- The kubelet on each node
- The containerd image cache
Show answer
A. The CLI sends API calls to the daemon over the unix socket.
Which command starts Docker now and at every boot?
- sudo systemctl enable --now docker
- sudo docker run --restart always
- sudo service docker logs -f now
- sudo chmod 666 docker.sock
Show answer
A. enable --now both starts the service and enables it at boot.
Docker fails right after editing daemon.json. Check what?
- The JSON syntax in the file
- The Docker Hub login token
- The container memory limit
- The image tag in the Dockerfile
Show answer
A. One stray comma in daemon.json stops dockerd from starting.
On Windows, what does Docker Desktop need to run Linux images?
- A working WSL 2 backend
- A running IIS web server
- The Hyper-V web console
- 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.