DEV Community

Big Mazzy
Big Mazzy

Posted on

Fix Cannot Connect to Docker Daemon on Ubuntu 24.04

TL;DR: On a test VM with no containers you need, check whether Docker is inactive and start it with sudo systemctl start docker.

The problem

You run a Docker command on Ubuntu 24.04 and get a connection error instead of a container list:

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Enter fullscreen mode Exit fullscreen mode

This means the Docker client cannot reach the daemon through its default Unix socket. The command itself may be fine; the daemon may simply be stopped.

The steps below reproduce that situation by stopping Docker, check its state, start it again, and verify that it responds. Use this procedure only on a test virtual machine with no containers you need. It uses a local Docker Engine with its default socket.

Why it happens

Docker has a client and a daemon. The docker command is the client; the daemon runs as a system service and handles requests such as listing containers. If the daemon is not running, the client cannot get a response through /var/run/docker.sock.

On this test VM, the socket and Docker services are stopped deliberately to reproduce the failure. The sudo docker ps command then demonstrates what the error looks like. Checking the Docker service state helps confirm the cause before you start it again.

Step-by-step fix

  1. Use a safe test environment. Do not stop Docker on a real server or a machine running containers you depend on. These commands reproduce the issue by stopping socket activation first and then stopping Docker. After that, list containers with sudo to see the connection error. IP addresses, process IDs (PIDs), and session numbers in examples are placeholders where relevant.
   sudo systemctl stop docker.socket
Enter fullscreen mode Exit fullscreen mode
   sudo systemctl stop docker
Enter fullscreen mode Exit fullscreen mode
   sudo docker ps
Enter fullscreen mode Exit fullscreen mode
  1. Check whether Docker is active. Query the service state:
   sudo systemctl is-active docker
Enter fullscreen mode Exit fullscreen mode

For this reproduction, the expected sample output is:

   inactive
Enter fullscreen mode Exit fullscreen mode

inactive confirms that the Docker service is stopped. If your situation differs, use the state shown by the command to guide your diagnosis rather than assuming the daemon is down.

  1. Start the Docker service. Once you have confirmed that the service is inactive, start it with system control:
   sudo systemctl start docker
Enter fullscreen mode Exit fullscreen mode

Starting Docker should make the daemon available again through its default Unix socket.

  1. Repeat the container listing. Use the same listing command to check whether the client can now reach the daemon:
   sudo docker ps
Enter fullscreen mode Exit fullscreen mode

How to verify

A successful response includes the container table header:

CONTAINER ID   IMAGE   COMMAND   CREATED   STATUS   PORTS   NAMES
Enter fullscreen mode Exit fullscreen mode

The header proves the daemon responded to the request. An empty list is fine: it means Docker answered, and there are no running containers to show. The important change is that the command now returns the table instead of the connection error.

If you still see a connection error, check the service state again with the command above and make sure the start step completed. Keep this reproduction limited to a test VM; stopping Docker on a server can interrupt workloads.

Common mistakes

  • Skipping the safety check: stopping the socket and Docker services is only for a test VM with no containers you need.
  • Starting the wrong thing first: the reproduction stops docker.socket before docker. Follow that order when recreating the issue.
  • Mistaking an empty list for failure: the table header means the daemon responded, even when no containers appear.
  • Treating the client as the daemon: docker ps requests information; the Docker service must be running to answer it.

If you want a clean Ubuntu box to practice on, PowerVPS is a reasonable choice: https://powervps.net/?from=32

Watch more fixes on Server Lab: https://www.youtube.com/channel/UCov7rfWAnS4c2wF5E9V1Yag

Top comments (0)