How to use Docker without sudo?

Running docker with sudo every single time gets old really fast. If you’re on Linux and you’ve installed Docker, chances are you’ve already bumped into this:

$ docker ps
Got permission denied while trying to connect to the Docker daemon socket...

Yeah, annoying. But don’t worry — there’s a proper fix for this that doesn’t involve bad security practices like setting Docker to run as rootless in unsafe ways. Here’s how you can run Docker commands without needing sudo.

Step 1: Add Your User to the Docker Group

Docker runs as a daemon with root privileges, and by default, only users in the docker group can interact with it without sudo.

To add your user:

sudo usermod -aG docker $USER

What this does is append your current user to the docker group. This tells the system, “Hey, this person can access Docker without asking for root privileges every time.”

Step 2: Log Out and Log Back In

This part is easy to forget — but important. The group change won’t take effect until you log out and log back into your session.

If you’re in a hurry and don’t want to log out completely, you can just run:

newgrp docker

This updates your group membership in the current shell. After that, try again:

docker ps

If all went well, it should work without sudo.

Step 3: Test It Out

Try pulling an image and running a quick container:

docker run hello-world

If it runs and prints out the welcome message without asking for sudo, congrats — you’re good to go.

Optional: Verify Your Group Membership

If you want to double-check you’re in the right group, just run:

groups

You should see docker listed among your groups. That’s it. clean, secure, and no more typing sudo docker every time. If you’re managing Docker containers frequently, this tweak will save you time and improve your workflow.

Share:

More Posts

How to Install Maven on macOS 2025

What you will read?1 Check for Java Installation2 Install Homebrew (If Not Installed)3 Install Maven via Homebrew4 Verify Environment Variables (Optional)5 Create a Sample Maven

How to Use Google SMTP Server

What you will read?1 Step 1: Enable SMTP Access in Gmail2 Step 2: Secure Connection with TLS3 Step 3: Send an Email via SMTP4 Step

how to install wine on RHEL

What you will read?1 Check RHEL version and CPU architecture2 Update system and install base tools3 Verify subscription and enable CodeReady Builder4 Enable EPEL repository5

Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments