Why is adding a user to the docker group effectively the same as giving them root?
Group members get full access to the Docker daemon, which runs as root, and can ask it to start a container that mounts the host's / and gives them a root shell on it.
sudo usermod -aG docker labadmin lets labadmin run docker without sudo, because the group may open the daemon's socket /var/run/docker.sock. But the daemon runs as root and will do whatever it is asked, for example:
docker run -it -v /:/host alpine chroot /host sh
This starts a container whose root user has the host's entire filesystem mounted, and leaves the user in a root shell on the host's files: they can read /etc/shadow, add themselves to sudoers or install a backdoor. No password, no sudo log entry.
Consequences:
- Treat
dockergroup membership likesudorights and grant it only to trusted administrators. - The group change only applies after logging out and in again (the session's group list is fixed at login).
- Alternatives that remove the problem: rootless Docker or Podman's rootless mode, where the container engine runs with the user's own privileges.
* Group membership, socket access, root daemon, host root shell. *
Go deeper:
Docker Docs: Linux post-installation steps — the official warning that the docker group grants root-level privileges.
Docker Docs: Rootless mode — running the daemon and containers without root.