The Problem
New team member ran docker ps on a Linux server and got:
permission denied while trying to connect to the Docker daemon socket
at unix:///var/run/docker.sock
What Happened
The user wasn't in the docker group. On Linux, the Docker socket is owned by root:docker. If your user isn't in the docker group, you can't connect.
The Fix
# Add user to the docker group
sudo usermod -aG docker $USER
# Apply group change without logging out
newgrp docker
# Verify it worked
docker psIf newgrp doesn't work, log out and back in — the group membership needs to refresh.
Check Group Membership
# See all groups for current user
groups
# Should include 'docker'
# ubuntu adm cdrom sudo dip plugdev lpadmin sambashare dockerIn CI/CD (if this happens in a pipeline)
# In Dockerfile or CI runner setup
RUN usermod -aG docker jenkins # or whatever the CI user is
# Or run the docker command with sudo (not recommended)
# Or use Docker-in-Docker (dind) properly with the right socket mountSecurity Note
Adding a user to the docker group is essentially giving them root access. The docker socket has full control over the host. On production servers, be deliberate about who's in this group.