How to fix docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock in Docker

DockerBEGINNERMEDIUMUpdated Dec 6, 2025ยท 296 views

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
  1. Verify the Docker daemon is running
  2. Create the docker group (if needed)
  3. Add your user to the docker group
  4. Apply the group changes
docker โ€” error
sudo systemctl status docker
docker: 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

  1. User is not a member of the docker group
  2. Group membership changes haven't taken effect (haven't logged out/in)
  3. Docker was installed but post-installation steps were skipped
  4. Docker daemon socket has incorrect permissions
  5. ~/.docker directory was created with wrong permissions (from running docker with sudo)
  6. 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"

1Verify the Docker daemon is running

First, ensure the Docker daemon is actually running:

bash
sudo systemctl status docker

If Docker is not running, start it:

bash
sudo systemctl start docker

To enable Docker to start on boot:

bash
sudo systemctl enable docker
2Create the docker group (if needed)

The docker group may not exist on some systems. Create it:

bash
sudo groupadd docker

If the group already exists, you'll see a message saying so - that's fine.

3Add your user to the docker group

Add your current user to the docker group:

bash
sudo usermod -aG docker $USER

The -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:

bash
sudo usermod -aG docker username
4Apply the group changes

For 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)

bash
newgrp docker

This activates the docker group in your current shell session without logging out.

Option 3: Reboot (if other methods don't work)

bash
sudo reboot
5Verify the fix

Test that Docker works without sudo:

bash
docker run hello-world

You should see a "Hello from Docker!" message without any permission errors.

Also verify your group membership:

bash
groups

You should see docker in the list of groups.

6Fix ~/.docker directory permissions (if needed)

If you previously ran Docker with sudo, the ~/.docker directory may have incorrect ownership:

bash
sudo chown "$USER":"$USER" /home/"$USER"/.docker -R
sudo chmod g+rwx "$HOME/.docker" -R

This 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:

bash
dockerd-rootless-setuptool.sh install

Rootless 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:

bash
sudo ausearch -m avc -ts recent

If 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