How to fix docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock in Docker
This error occurs when your user account lacks permission to access the Docker daemon socket at /var/run/docker.sock. The fix is to add your user to the docker group, which grants the necessary permissions without using sudo for every command.
Quick fix
Fixes EACCES
sudo systemctl status docker- Verify the Docker daemon is running
- Create the docker group (if needed)
- Add your user to the docker group
- Apply the group changes
sudo systemctl status dockerdocker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock
What this error means
When you run Docker commands, the Docker CLI communicates with the Docker daemon through a Unix socket located at `/var/run/docker.sock`. This socket is owned by root and the docker group, with permissions that only allow root users and members of the docker group to access it. This error appears because: - Your user is not a member of the `docker` group - You're running Docker commands without `sudo` - The Docker daemon is running with default permissions The Docker daemon always runs as root. By default, the Unix socket it creates is owned by `root:docker` with permissions `srw-rw----`, meaning only root and docker group members can communicate with the daemon.
Typical symptoms
- Docker commands fail with 'permission denied' unless run with sudo
- Running 'docker ps' or 'docker images' returns permission errors
- CI/CD pipelines fail when trying to build or run containers
- Docker Compose commands fail with socket connection errors
- IDEs and tools that integrate with Docker cannot connect
Common causes
- User is not a member of the docker group
- Group membership changes haven't taken effect (haven't logged out/in)
- Docker was installed but post-installation steps were skipped
- Docker daemon socket has incorrect permissions
- ~/.docker directory was created with wrong permissions (from running docker with sudo)
- SELinux or AppArmor blocking socket access
How to fix "docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock"
First, ensure the Docker daemon is actually running:
sudo systemctl status dockerIf Docker is not running, start it:
sudo systemctl start dockerTo enable Docker to start on boot:
sudo systemctl enable dockerThe docker group may not exist on some systems. Create it:
sudo groupadd dockerIf the group already exists, you'll see a message saying so - that's fine.
Add your current user to the docker group:
sudo usermod -aG docker $USERThe -aG flags mean:
- -a: Append to the group (don't remove from other groups)
- -G: Specify the group name
You can also add a specific user:
sudo usermod -aG docker usernameFor the group membership to take effect, you have several options:
Option 1: Log out and log back in
This is the most reliable method. Close your terminal, log out of your desktop session, and log back in.
Option 2: Use newgrp (immediate, current shell only)
newgrp dockerThis activates the docker group in your current shell session without logging out.
Option 3: Reboot (if other methods don't work)
sudo rebootTest that Docker works without sudo:
docker run hello-worldYou should see a "Hello from Docker!" message without any permission errors.
Also verify your group membership:
groupsYou should see docker in the list of groups.
If you previously ran Docker with sudo, the ~/.docker directory may have incorrect ownership:
sudo chown "$USER":"$USER" /home/"$USER"/.docker -R
sudo chmod g+rwx "$HOME/.docker" -RThis ensures your user owns the Docker configuration directory.
Advanced notes
Security Considerations:
Adding users to the docker group is effectively granting them root-equivalent privileges. Docker containers can be used to escalate privileges on the host system. Only add trusted users to this group.
Rootless Mode Alternative:
For better security, consider running Docker in rootless mode:
dockerd-rootless-setuptool.sh installRootless mode runs the Docker daemon and containers entirely in user space without requiring root privileges. See the official Docker documentation for setup details.
SELinux Considerations (RHEL/CentOS/Fedora):
If you're on a system with SELinux and still having issues after adding your user to the docker group:
sudo ausearch -m avc -ts recentIf SELinux is blocking access, you may need to adjust SELinux policies or temporarily set it to permissive mode for troubleshooting.
Temporary Workaround (Not Recommended for Production):
Running sudo chmod 666 /var/run/docker.sock will allow anyone to access Docker, but this is a serious security risk. Anyone on the system could control Docker, potentially leading to container escapes or system compromise. Use this only for temporary debugging on isolated systems.
Virtual Machine Considerations:
When running Docker inside a VM, you may need to restart the entire VM for group changes to take effect, as some hypervisors cache user sessions.
Frequently asked questions
- What does "EACCES" mean?
- sock. This socket is owned by root and the docker group, with permissions that only allow root users and members of the docker group to access it. This error appears because: - Your user is not a member of the docker group - You're running Docker commands without sudo - The Docker daemon is running with default permissions The Docker daemon always runs as root.
- How do I fix "EACCES"?
- This error occurs when your user account lacks permission to access the Docker daemon socket at /var/run/docker.sock. The fix is to add your user to the docker group, which grants the necessary permissions without using sudo for every command.
- What causes "EACCES"?
- User is not a member of the docker group Group membership changes haven't taken effect (haven't logged out/in) Docker was installed but post-installation steps were skipped
- Is the "EACCES" error serious?
- It is a medium-severity error โ more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- ๐Docker Official Documentation
- ๐ฌ
- ๐ฌHow to fix Docker: Permission denied - Stack Overflow(Stack Overflow)
- ๐ฌdocker.sock permission denied - Stack Overflow(Stack Overflow)
- ๐ฌHow to fix docker permission denied - DigitalOcean(Stack Overflow)
- ๐ฌHow to fix docker permission denied - Better Stack(Stack Overflow)
- ๐
- ๐How to fix the permission denied error in Docker - Hostinger(Official Docs)
- ๐
- ๐ฌHow to fix Permission Denied While Trying to Connect - Medium(Stack Overflow)
- ๐