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

2026-10-07来源 dev.to DockerEnglish

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 

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 

Verify it works without sudo:

docker ps 

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 

Check status:

sudo systemctl status docker 

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 

⚠️ 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.

原文:https://www.a8q9.cn/en/article/fix-permission-denied-while-trying-to-connect-to-the-docker-daemon-socket-on-lin-b689b8.html

相关文章