Cause 1 of 5
Your Linux user is not in the docker group.
sudo usermod -aG docker $USER, then log out and back in — or run newgrp docker in the current shell — so the new group takes effect. Know the trade-off before you do it: membership of the docker group is equivalent to root on that host, because anyone in it can start a container that mounts the whole filesystem.
Cause 2 of 5
You would rather not grant root-equivalent access.
Use rootless Docker, installed with dockerd-rootless-setuptool.sh install, or Podman, which runs containers as your own user with no daemon at all. On a shared or sensitive machine this is the better answer, not a compromise.
Cause 3 of 5
The daemon is not running.
Check with systemctl status docker and start it with sudo systemctl start docker. On macOS and Windows, start Docker Desktop — the socket exists but nothing is answering behind it.
Cause 4 of 5
A CI job or a container needs access to the socket.
Mounting /var/run/docker.sock into a container gives that container full control of the host, so anything it runs is effectively root. Prefer a rootless builder, a dedicated build service, or Docker-in-Docker with a scoped runner; if you must mount it, tightly control what runs inside.
Cause 5 of 5
You just want the one command to work.
sudo docker ... runs, but it leaves root-owned files behind in bind-mounted project directories and hides the setup problem. Fix the group membership or move to rootless instead of making sudo the habit. Never run chmod 666 /var/run/docker.sock — that hands every local account root on the machine.