Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Fix Docker Error: Permission Denied to Docker Daemon Socket (Without Sudo)

 


You just installed Docker, you’re excited to run your first container, and you type docker ps. Instead of a list of containers, you get this:

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

Why is this happening?

By default, the Docker daemon binds to a Unix socket which is owned by the root user. Because you are logged in as a regular user, you don't have the permissions to access that socket.

Most people "fix" this by typing sudo before every command, but that is dangerous and bad practice. Here is the professional way to fix it once and for all.

Step 1: Create the Docker Group

In most modern installations, this group already exists, but let’s make sure:

sudo groupadd docker

Step 2: Add your User to the Group

This command adds your current logged-in user to the docker group so you have the necessary permissions.

sudo usermod -aG docker $USER

Step 3: Activate the Changes

Important: Your terminal doesn't know you've joined a new group yet. You can either log out and log back in, or run this command to refresh your group memberships immediately:

newgrp docker

Step 4: Verify the Fix

Now, try running a command without sudo:

docker run hello-world

If you see the "Hello from Docker!" message, you’ve successfully fixed the permission issue!

Note:

Adding a user to the "docker" group is equivalent to giving them root privileges. Only add users you trust. If you are in a highly secure environment, consider using Rootless Docker, which allows you to run containers without needing root access at all.

Reduce AWS Bills by 60%: Automate EC2 Stop/Start with Python & Lambda

In 2026, cloud bills have become a top expense for most tech companies. One of the biggest "money-wasters" is leaving Development ...