Permission denied
The system rejected a Docker operation because the current user lacks the required read/write permissions for files, sockets, or directories.
Usually happens because:
- ☑ User not in docker system group
- ☑ Volume mount directory owned by root
- ☑ Incorrect socket file permissions
🔍 Quick Checklist:
What is Permission denied?
This error occurs when the Docker daemon or client attempts to perform an operation (like reading a local file for a build, mounting a volume directory, or writing output files) but is blocked by the host operating system's security controls. It most commonly manifests when running commands without the 'sudo' prefix before your user has been added to the docker system group.
Common Causes
- User not in Docker Group: The active shell user is not listed inside the system's docker group.
- Volume mount permission mismatch: Mounting host directories that have root-only ownership inside containers running under non-root users.
- Dockerfile copy access blocked: Trying to COPY files that are protected or owned by different system accounts.
| Cause | Frequency |
|---|---|
| User missing from docker group | ⭐⭐⭐⭐⭐ |
| Host volume mount permissions mismatch | ⭐⭐⭐⭐ |
| File permissions in COPY/ADD | ⭐⭐⭐ |
Common Mistakes
- Running all docker commands with sudo, which creates root-owned files on your host machine that are hard to edit later.
- Forgetting to restart the terminal or log out after adding the user to the docker group.
How to Fix
Docker Operations & Verification
If a container runs as a non-root user (e.g. node, uid 1000) and mounts a host directory owned by root, it will throw permission errors when writing.
# Inspect host folder ownership
ls -ld ./data
# Fix: Change ownership to match container user
sudo chown -R 1000:1000 ./dataPlatform Specific Fixes
Adding the active user to the docker group on Linux hosts.
sudo usermod -aG docker $USER
# Apply group changes immediately without logging out
newgrp dockerBest Practices
- Always declare non-root users inside your custom Dockerfiles (`USER node` or `USER 1000`).
- Ensure host directory permission properties match container execution users.
Frequently Asked Questions (FAQ)
Q: Why does Docker say permission denied?
The client lacks access to read/write system resources (like docker.sock or host directories).
Q: Should I run Docker commands using sudo?
Ideally no. Prepending sudo can cause files created inside the container to belong to root, causing permissions issues later. Add your user to the docker group instead.
Q: How do I fix permission denied on volume mounts?
Ensure the folder on your host machine has read/write permissions matching the user running inside the container.
Q: How do I reload group settings without rebooting?
Run the 'newgrp docker' command to apply group changes immediately in the active terminal shell.