Imagine you walk into a restaurant and tell the waiter, “One pizza, please.” The waiter smiles, walks to the kitchen… and finds the kitchen door locked. Nobody is cooking. Your pizza will never come, no matter how nicely you ask.
That is exactly what happens when you type a Docker command and your terminal shouts back: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
The good news? It is one of the easiest Docker errors to fix. In most cases you only need two or three short commands. In this guide, I will show you the commands first, then explain what is going on in plain words, so you never feel lost the next time it pops up.
Quick Summary: The News in 30 Seconds
- The docker command you type is only a messenger (the “client”). The real worker is a background program called the Docker daemon.
- The error means the messenger could not reach the worker. Either the worker is not running, or you are not allowed in, or the messenger is looking at the wrong address.
- On Linux, start the worker with sudo systemctl start docker.
- If you see “permission denied”, add yourself to the docker group with sudo usermod -aG docker $USER, then log out and log back in.
- On WSL2, a Linux distro does not run Docker by default. Either turn on Docker Desktop’s WSL integration, or install Docker inside WSL2 and start it.
- Docker’s own documentation warns that the docker group gives power equal to the root user, so use it with care.
Quick Fix: Copy-Paste Commands for Linux
Open your terminal and follow these steps in order. After each step, try your Docker command again. If it works, you can stop right there.
Step 1: Check if Docker is running
First, ask your computer if the Docker service is alive:
sudo systemctl status docker
If you see the word active (running), the daemon is fine, so skip to Step 4. If you see inactive, dead or failed, go to Step 2.
Step 2: Start the Docker service
sudo systemctl start docker
This is like unlocking the kitchen door and turning on the stove. Now check again with the status command from Step 1.
Step 3: Make Docker start by itself after every restart
Many people see this error right after turning their computer off and on. That happens because Docker was not set to start at boot. Fix it once, and it stays fixed:
sudo systemctl enable docker
Think of it as telling the cook, “Please come to work every morning without me calling you.”
Step 4: Fix user permissions
Now the second common cause. By default, the Docker socket belongs to the root user, and other users can only use it with sudo. If your terminal says permission denied instead, add yourself to the docker group:
sudo usermod -aG docker $USER
Important: this does nothing until your computer re-reads your group list. Log out and log back in. Or, for a quick test in the same window, run:
newgrp docker
On some systems the group does not exist yet. If you get a “group does not exist” message, create it first, then run the usermod command again:
sudo groupadd docker
Step 5: Test that it works
docker run hello-world
If you see a friendly “Hello from Docker!” message, you are done. Well done!
Quick Fix: Start Docker in WSL2 (Windows)
WSL2 lets you run Linux inside Windows. But here is a surprise that trips up many beginners: a WSL distribution does not run a Docker daemon on its own. So when you type docker ps in your Ubuntu window, the client has nobody to talk to.
You have two good choices. Pick one, not both.
Path A: Use Docker Desktop with WSL integration (easiest)
With this path, Docker Desktop on Windows runs the daemon, and your Linux window simply talks to it.
- Start Docker Desktop from the Windows Start menu and wait until it says it is running.
- Open Docker Desktop, then go to Settings and the General tab. Make sure Use WSL 2 based engine is ticked.
- Go to Settings > Resources > WSL Integration. Turn on integration for your default distro, and for any extra distro you use, such as Ubuntu.
- Click Apply, then close and reopen your WSL terminal.
- Run docker run hello-world to test.
Not sure which distro is your default? In PowerShell, you can list your distros and set the default like this:
wsl --list --verbose
wsl --set-default Ubuntu
Replace Ubuntu with the name of your own distro. One more tip from Docker’s guide: if you earlier installed Docker Engine directly inside the distro, remove it before relying on Docker Desktop, because the two can clash.
Path B: Run Docker Engine inside WSL2 using systemd
Maybe you do not want Docker Desktop. Then you install Docker Engine inside your WSL2 distro, just like on a normal Linux machine. For the service to start properly, your distro needs systemd, the Linux helper that starts and stops background services.
Microsoft’s instructions are short. Inside your WSL distro, open the file /etc/wsl.conf with admin rights:
sudo nano /etc/wsl.conf
Add these two lines:
[boot]
systemd=true
Save the file. Now close your WSL windows. In Windows PowerShell, restart all WSL instances:
wsl.exe --shutdown
Open your distro again. Systemd should now be running, so the same commands from the Linux section work:
sudo systemctl start docker
sudo systemctl enable docker
sudo usermod -aG docker $USER
Then close and reopen the WSL window (so your new group is picked up) and test with docker run hello-world.
If systemd support does not work, your WSL may be too old. Microsoft says you need a recent version, and you can check for updates by running wsl –update in PowerShell.
No systemd? Try the older way
If your distro does not use systemd, the systemctl command may complain that the system was not booted with systemd. In that case, many people start the service the older way:
sudo service docker start
You may need to run this each time you open WSL. That is why turning on systemd is the cleaner long-term answer.
What Does This Scary Error Actually Mean?
Let us break the sentence into small pieces, like cutting a sandwich.
The client
The word docker at the start of your command is the client. It is just the person who takes your order. It does not cook anything. It only passes your request along.
The daemon
A daemon is a program that works quietly in the background. Docker’s daemon is called dockerd. It is the cook in the kitchen. It builds images, starts containers and does all the heavy work.
The socket
How do the client and daemon talk? Through a socket. Picture the little service window between the waiter and the kitchen. On Linux, this window is a special file at /var/run/docker.sock. The unix:// part of the message just says “we talk through a Unix socket file”.
Putting it together
So the full message means: “I tried to pass your order through the window at /var/run/docker.sock, but nobody answered. Is the kitchen open?” That is why the error ends with a question.
Newer Docker versions may phrase it a bit differently, for example “failed to connect to the docker API at unix:///var/run/docker.sock; check if the path is correct and if the daemon is running”. The meaning is the same.
Two Errors That Look the Same But Are Not
This is the part most guides skip, and it saves a lot of time. Two different problems can look alike:
| What you see | What it means | Kitchen analogy | Fix |
|---|---|---|---|
| Cannot connect to the Docker daemon… Is the docker daemon running? | Nothing is listening on the socket, or the client is pointed at the wrong place | The kitchen is closed | Start the daemon, check DOCKER_HOST |
| permission denied while trying to connect to the Docker daemon socket | The daemon is running, but your user cannot open its socket | The kitchen is open, but you have no key to the service window | Add your user to the docker group |
One guide puts it nicely: starting the daemon will not fix a permission error, and fixing permissions will not fix a stopped daemon. So read your exact message first. It tells you which fix to try.
Other Reasons You Might See This Error
If the quick fixes did not work, do not panic. Here are the next suspects.
1. A leftover DOCKER_HOST setting
Your computer can have a setting called DOCKER_HOST. It tells the client where to find the daemon. If an old value is left behind, the client keeps knocking on the wrong door. It is like writing the wrong address on a letter. Check it, and clear it if you do not need it:
echo $DOCKER_HOST
unset DOCKER_HOST
One troubleshooting guide shows a version of this problem where the message mentions tcp://localhost:2375 instead of the socket path. The cure is the same: remove the stale setting.
2. The wrong Docker context
Docker can remember several places it may talk to. Each place is called a context. If your active context points to a place that is switched off, you get the error. List your contexts and switch back to the local one:
docker context ls
docker context use default
3. Docker Desktop on Linux works a little differently
If you use Docker Desktop on Linux (instead of plain Docker Engine), be aware that it does not use /var/run/docker.sock. Its CLI talks to a different socket through the desktop-linux context. So the docker command can work fine, while some other tool that is hard-coded to use /var/run/docker.sock still fails with this very error. If that is your case, check your contexts and the tool’s settings.
4. The socket file has wrong permissions
Take a peek at the socket file:
ls -l /var/run/docker.sock
A healthy socket is usually owned by root and the docker group, and allows read and write for both. If it looks wrong, one guide suggests resetting it like this:
sudo chown root:docker /var/run/docker.sock
sudo chmod 660 /var/run/docker.sock
Only try this after the simpler fixes. In most cases the socket is fine and the group or the daemon is the real problem.
5. You used sudo first, then fixed the group later
Here is a sneaky one from Docker’s own guide. If you ran Docker commands with sudo before adding yourself to the docker group, your ~/.docker folder may have been created with the wrong owner. You may then see a warning about “Error loading config file” and “permission denied”. The fix is to give the folder back to yourself:
sudo chown "$USER":"$USER" /home/"$USER"/.docker -R
sudo chmod g+rwx "$HOME/.docker" -R
6. The daemon tries to start but crashes
Sometimes systemctl start docker runs, but the service stops again right away. Ask the logs what happened:
sudo systemctl status docker
sudo journalctl -u docker --no-pager | tail -n 30
The last lines usually name the problem. One thing worth checking is free disk space, because a full disk can stop Docker from working. You can look at the space where Docker keeps its data with df -h /var/lib/docker.
Which Fix Should You Try? A Handy Table
| Your situation | Try this first |
|---|---|
| Error appeared right after restarting Linux | sudo systemctl start docker then sudo systemctl enable docker |
| Message says “permission denied” | sudo usermod -aG docker $USER, then log out and in |
| Only works with sudo | You are not in the docker group yet (or have not re-logged in) |
| Using WSL2 with Docker Desktop | Open Docker Desktop and turn on WSL Integration for your distro |
| Using WSL2 with Docker Engine inside it | Turn on systemd in /etc/wsl.conf, run wsl.exe –shutdown, then start Docker |
| Message mentions tcp://localhost:2375 | unset DOCKER_HOST |
| Docker works in terminal but another tool fails | Check docker context and which socket that tool expects |
Is the Docker Group Safe? An Honest Warning
Adding yourself to the docker group is the most popular fix, so it is only fair to tell you the catch. Docker’s documentation says plainly that the docker group gives you privileges equal to the root user. Root is the “boss account” on Linux that can do almost anything.
Here is a school example. Giving someone a master key to every classroom is handy for the caretaker. But you would not hand that key to every student. On your own laptop, where you are the only user, this is usually fine. On a shared or work server, think twice and ask your admin.
If you want to run Docker without root-level power, Docker offers something called rootless mode. It runs the daemon as a normal user instead. It has its own setup steps, so read the official guide before you switch.
Also, be careful about the “quick” habit of typing sudo docker in front of everything. It works, but it only hides the real problem, which is that your user is not set up correctly. It can also cause the folder-ownership trouble we saw above.
How to Stop This Error from Coming Back
- Enable the service at boot. Run sudo systemctl enable docker once on Linux.
- Re-login after group changes. New group membership is only read at login. This one tip fixes many “it still does not work” moments.
- Read the exact words. “Cannot connect” and “permission denied” need different fixes.
- Keep WSL and Docker Desktop updated. Old versions are a common source of strange behavior.
- Pick one Docker setup in WSL2. Do not mix Docker Desktop and an engine inside the distro unless you know why.
- Do not leave old environment settings around. If you once pointed Docker at a remote machine, remember to undo it.
- Check the logs first when it crashes. Use journalctl instead of guessing.
A Simple Troubleshooting Routine to Remember
Memorize this tiny checklist, like a school morning routine: brush teeth, pack bag, eat breakfast.
- Is the kitchen open? Run sudo systemctl status docker.
- Do I have a key? Run groups and look for docker in the list.
- Am I at the right address? Run echo $DOCKER_HOST and docker context ls.
- Is the window broken? Run ls -l /var/run/docker.sock.
- Am I in WSL2? Check Docker Desktop integration, or systemd.
Five quick checks, and you will solve this error in a couple of minutes next time.
Reminder: Check the Official Pages
Docker, Docker Desktop and WSL change often. Menu names, supported versions and recommended steps can shift after an update. Before you follow any guide (including this one) on an important machine, take a quick look at the official Docker documentation and the Microsoft WSL documentation for the latest steps.
Simple Word List (Glossary)
- Docker: A tool that packs an app and everything it needs into a neat box called a container.
- Container: A small, ready-to-run box that holds an app. Like a lunchbox with everything inside.
- Docker client (CLI): The docker command you type. It takes your order.
- Docker daemon (dockerd): The background program that does the real work. The cook.
- Socket: A special file that lets two programs talk. The service window.
- Unix socket: A socket that lives as a file on Linux, such as /var/run/docker.sock.
- systemd / systemctl: The Linux helper that starts and stops background services, and the command you use to talk to it.
- Root: The all-powerful boss account on Linux.
- sudo: A word that means “run this as the boss, just this once”.
- docker group: A club of users allowed to use the Docker socket without sudo.
- WSL2: Windows Subsystem for Linux version 2. Lets you run Linux inside Windows.
- Docker Desktop: A Docker app for Windows, Mac and Linux with buttons and settings.
- DOCKER_HOST: A setting that tells the client where the daemon lives.
- Context: A saved choice of which Docker daemon the client should talk to.
- Rootless mode: A way to run Docker without root-level power.
Frequently Asked Questions (FAQ)
1. What does “Cannot connect to the Docker daemon” mean?
It means the docker command (client) could not reach the Docker daemon (the background worker). Usually the daemon is stopped, or the client is pointed at the wrong place.
2. What is /var/run/docker.sock?
It is the Unix socket file that Docker’s client and daemon use to talk on Linux. Think of it as the service window between the waiter and the kitchen.
3. What is the fastest fix on Linux?
Run sudo systemctl start docker. If the message says permission denied instead, run sudo usermod -aG docker $USER and log out and back in.
4. I ran usermod but it still fails. Why?
Your computer only reads your new group list when you log in. Log out and back in, or run newgrp docker for the current window. Then test again.
5. Why does this error appear after every restart?
The Docker service is probably not set to start at boot. Run sudo systemctl enable docker once to fix it.
6. Why does Docker not work in my WSL2 terminal?
A WSL distro does not run a Docker daemon by default. Either enable WSL Integration in Docker Desktop, or install Docker Engine inside the distro and start it (with systemd turned on).
7. How do I turn on systemd in WSL2?
Add [boot] and systemd=true to /etc/wsl.conf inside your distro, then run wsl.exe –shutdown from PowerShell and reopen the distro.
8. Is it safe to add my user to the docker group?
Docker’s docs say the group gives root-equivalent power. It is usually fine on your own laptop, but be careful on shared machines. Rootless mode is an alternative.
9. Should I just type sudo before every docker command?
It may work, but it hides the real problem and can cause folder-ownership issues. It is better to fix your group membership.
10. Can DOCKER_HOST cause this error?
Yes. If an old value points to a daemon that is not there, you get a connection error. Run unset DOCKER_HOST and try again.
Final Thoughts
The “Cannot connect to the Docker daemon” error looks scary, but now you know the secret: it is almost always a closed kitchen, a missing key, or a wrong address. Start the service, fix your group, check your settings, and in WSL2 choose one clean setup. That is it.
Did this guide fix your problem? Tell me in the comments which step solved it for you, and if you are stuck, share the exact message you see and your setup (Linux or WSL2) so other readers can help too.
At Connect Digital World, we explain tech problems in simple words, so come back soon for more easy guides on Docker, Linux and everyday tech.
Sources and further reading: Docker Docs, “Linux post-installation steps for Docker Engine” (docs.docker.com/engine/install/linux-postinstall/); Docker Docs, “Docker Desktop WSL 2 backend on Windows” (docs.docker.com/desktop/wsl); Microsoft Windows Command Line blog, “Systemd support is now available in WSL” (devblogs.microsoft.com/commandline/systemd-support-is-now-available-in-wsl/); Microsoft Learn, “Advanced settings configuration in WSL” (learn.microsoft.com/en-us/windows/wsl/wsl-config); troubleshooting guides from Dash0 (dash0.com/faq/how-to-fix-cannot-connect-to-the-docker-daemon), Inventive HQ (inventivehq.com/knowledge-base/devops/cannot-connect-to-the-docker-daemon), Rocketeers (rocketee.rs/cannot-connect-to-docker-daemon) and MakeTechEasier (maketecheasier.com/fix-cannot-connect-to-docker-daemon-error).

