🎓 A1Learner
🔍
0 of 50 lessons completed

Docker Without sudo

Docker without sudo means adding your user to the docker group. The group owns the daemon socket, so its members can run Docker without sudo.

Add your user to the group

This command adds the current user to the docker group.

sudo usermod -aG docker $USER

Join the group now

This command starts a shell with the new group, without logging out.

newgrp docker

Check your groups

This command lists the groups your user belongs to.

id -nG

Example

docker run hello-world

Key points

  • Group: a set of users that share one permission on Linux.
  • The docker group owns the daemon socket, the file Docker uses to talk.
  • Add your user with sudo usermod -aG docker, then log out and back in.
  • Use newgrp docker to join the group in the current terminal without logging out.
  • Group membership is nearly root, because the daemon runs as root.
  • Rootless Docker runs the daemon as your own user, without the group.

In this example, Docker runs hello-world with no sudo in front. The command works because the user belongs to the docker group. The greeting proves the group membership took effect.

Note

Podman is an alternative that runs containers without a daemon at all.

Try it Yourself

Edit the code, then press Run.

Running is simulated · Rust Playground

Exercise

Why does adding a user to the docker group need care?