How to Fix Docker Permission Denied on DigitalOcean Droplet


The Root Cause

This error occurs because the user attempting to run Docker commands lacks the necessary permissions to communicate with the Docker daemon socket, located at /var/run/docker.sock. On a DigitalOcean Droplet, when Docker is installed, a docker group is created; however, newly created non-root users are not automatically added to this group, preventing them from interacting with Docker without sudo privileges.

Quick Fix (CLI)

Add your current user to the docker group and then apply the changes.

# Add the current user to the docker group
sudo usermod -aG docker ${USER}

# Apply the new group membership without logging out and back in
newgrp docker

Note: While newgrp docker can apply the changes to your current shell session, for persistent and system-wide application, logging out and logging back into your Droplet via SSH is recommended after running usermod.

Configuration Check

This specific “Docker Permission Denied” issue, arising from a user not being in the docker group, is a system-level user permission problem. It is not resolved by editing Docker configuration files (e.g., /etc/docker/daemon.json, Dockerfile, nginx.conf) or modifying application-specific settings. No file modifications are required for this particular fix; the resolution is solely via the user group management commands provided above.

Verification

Execute a simple Docker command to confirm that the permission issue has been resolved and your user can now interact with the Docker daemon.

docker run hello-world

A successful output will show messages indicating Docker pulled and ran the hello-world image, confirming daemon access.