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:
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:
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.
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:
Step 4: Verify the Fix
Now, try running a command without sudo:
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.

No comments:
Post a Comment