DevFlow logoDevFlow
PERMISSION_DENIEDVerified Production Fix

permission denied while trying to connect to the Docker daemon socket

Resolve "permission denied while trying to connect to the Docker daemon socket" on Linux and macOS. Add user to docker group safely without sudo.

Root Cause Mechanical Summary

The current non-root user lacks read/write permissions to `/var/run/docker.sock`. By default, only the root user and members of the `docker` user group can access the Docker engine socket.

The unix socket `/var/run/docker.sock` is owned by `root:docker` with `0660` permissions. Non-root users running docker commands without group membership receive EACCES.

Vulnerable / Problematic Syntax
Before
# Running docker as non-member
docker ps
# Output: permission denied while trying to connect to the Docker daemon socket...
Production-Safe Remediation
After
# Add current user to docker group and refresh shell session
sudo usermod -aG docker $USER
newgrp docker
docker ps # Works without sudo!

Resolution Note: Add your active user account to the docker group and initialize the new group credentials.

Step-by-Step Triage Checklist

  • Check group membership: run `groups` and verify `docker` is listed.

  • Verify socket permissions: run `ls -la /var/run/docker.sock`.

  • If using rootless Docker, export `DOCKER_HOST=unix://$XDG_RUNTIME_DIR/docker.sock`.

Docker Group Verification in CI/CD Runner

scripts/verify-docker.sh

Prevent recurrence by enforcing this verification check in staging or pre-commit hooks:

if ! groups | grep -q "\bdocker\b"; then
  echo "User does not belong to docker group. Please run: sudo usermod -aG docker $USER"
  exit 1
fi

Quick CLI Fix / Diagnosis

sudo usermod -aG docker $USER && newgrp docker

Frequently Asked Questions

Is adding a user to the docker group a security risk?
Yes, granting access to the Docker socket allows root-equivalent privileges on the host system because containers can mount host directories.
Was this guide / tool helpful to you?