How to Run Docker Without Sudo: A Step-by-Step Guide

Tired of typing sudo before every Docker command? Learn how to add your user to the Docker group and run Docker without elevated privileges. This guide walks you through the process, along with important security considerations.

Banner

Running Docker without sudo can save time and improve your workflow. Here’s how to set it up safely.

Create the Docker Group (if it doesn’t already exist):

If the Docker group isn’t already created on your system, you need to add it. Run this command in your terminal:


sudo groupadd docker

Add Your User to the Docker Group:

Replace


$USER

with your username if necessary. This step grants your user permissions to run Docker commands without sudo.


sudo usermod -aG docker $USER

Re-login to Apply Changes:

After adding your user to the Docker group, you need to log out and back in. This ensures the group membership is refreshed. Alternatively, you can restart your session.

Test Docker Without Sudo:

Now, test whether Docker works without using sudo. Run the following command:


docker ps

Important Note on Security:

By adding your user to the Docker group, you’re giving it elevated privileges. Members of the Docker group can effectively gain root-level access through the Docker daemon. Be cautious:

Only add trusted users to the Docker group.
Be careful about running untrusted Docker images.
If your account is compromised, the attacker could gain root-like access via Docker.

Summary:

Running Docker without sudo makes things easier, but it’s important to understand the security trade-offs. Follow best practices to keep your system secure.

How to Run Docker Without Sudo: A Step-by-Step Guide | Software Engineer Blog