DEV Community

OneLineDev
OneLineDev

Posted on

Fix: 'permission denied while trying to connect to the Docker daemon socket' on Linux

The Error

You run docker ps or docker compose up on Linux and get hit with:

permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock
Enter fullscreen mode Exit fullscreen mode

Why It Happens

The Docker daemon runs as root and binds to a Unix socket owned by the docker group. If your current user account has not been added to that group, the operating system blocks access.


⚡ The Instant Fix (One-Liner)

Add your current user to the docker group and refresh your group membership immediately without logging out:

sudo usermod -aG docker $USER && newgrp docker
Enter fullscreen mode Exit fullscreen mode

Verify it works without sudo:

docker ps
Enter fullscreen mode Exit fullscreen mode

If the Docker Service Isn't Running

If you still get socket errors, ensure the Docker engine daemon is actively running:

sudo systemctl enable --now docker
Enter fullscreen mode Exit fullscreen mode

Check status:

sudo systemctl status docker
Enter fullscreen mode Exit fullscreen mode

WSL2 (Ubuntu on Windows) Fix

If you are running Docker inside WSL2 without Docker Desktop:

sudo service docker start
sudo usermod -aG docker $USER && newgrp docker
Enter fullscreen mode Exit fullscreen mode

⚠️ What NOT to Do

Never run sudo chmod 777 /var/run/docker.sock. While it works temporarily, it gives every user and malicious process on your machine unrestricted root privileges to your host system.

Top comments (0)