usermod cannot add your user to the docker group, or it seems to have no effect
usermod reports that group docker does not existShort answer
Create the group if it is missing, then add your user with usermod -aG docker. The -a matters: without it, usermod removes the user from every group not listed. Group changes reach a session only after a new login, or in one shell after newgrp docker.
Fix it fast
1Find out which cause you have
Check that the group exists, and compare the groups stored for your account with the ones your current shell has.
getent group docker id -nG id -nG "$USER"2Match what you see, then jump to its fix
- 1
usermod says the group does not exist, and getent group docker prints nothingThe docker group does not exist yetFix - 2
id -nG "$USER" shows docker, plain id -nG does not, and docker still says permission deniedThe membership exists but your running session does not have itFix - 3
after the command you lost sudo or another group you used to haveusermod -G without -a replaced your other groupsFix
- 1
What does the error look like?
usermod reports that group docker does not existid does not list docker after the command succeeded
Cause 1 of 3
The docker group does not exist yet
1Check
usermod only accepts groups that already exist. Installing Docker from a source other than the Docker packages, or a minimal image, may not create it.
getent group docker2Fix
Create the group, then add your user to it. Docker's post-install guide uses exactly these two commands.
sudo groupadd docker
sudo usermod -aG docker "$USER"3Verify
The account now lists docker.
id -nG "$USER"Confirmed by docs.docker.com
Cause 2 of 3
The membership exists but your running session does not have it
1Check
Groups are read when a login session starts. The shell you already have keeps the old list.
id -nG
id -nG "$USER"2Fix
Log out and back in, or start a shell that picks up the new group.
newgrp docker3Verify
Docker runs without sudo in that shell.
docker run --rm hello-worldConfirmed by docs.docker.com
Cause 3 of 3
usermod -G without -a replaced your other groups
1Check
With -G alone, any group the user belongs to that is not in the list is removed. Compare with the groups of a similar account.
id -nG "$USER"2Fix
Add the missing groups back, and use -a from now on. Run this from an account that still has sudo or from a root console.
sudo usermod -aG sudo,docker "$USER"3Verify
The account lists every group it needs.
id -nG "$USER"Confirmed by manpages.ubuntu.com
How do I stop it coming back?
- Always write usermod -aG, never -G alone, when adding to a group.
- Remember that the docker group grants root-level privileges; add only people who should have that.
- Put the group creation and usermod in your provisioning script, then log in again before testing.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Servers
Docker says permission denied when your user runs a command
Got permission denied while trying to connect to the Docker daemon socket
Your user is not allowed to open /var/run/docker.sock.
3 causes, each with a fixServers
Apache logs SIGWINCH and exits on its own
the httpd container stops although nothing crashed
SIGWINCH is Apache's graceful-stop signal.
2 causes, each with a fixServers
sam local fails: Running AWS SAM projects locally requires Docker
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
sam local start-api and sam local invoke run your function inside a Docker container, so SAM stops if it cannot talk to Docker.
3 causes, each with a fixServers
dnf fails to download repo metadata in a CentOS 8 Docker build
The same Dockerfile built fine before 2022
CentOS Linux 8 reached end of life on 31 December 2021 and its content left the mirrors.
2 causes, each with a fixServers
pip install confluent-kafka fails because librdkafka/rdkafka.h is missing
pip stops while building confluent-kafka from source
The error means pip is compiling confluent-kafka from source, and the compiler cannot find the librdkafka C headers.
3 causes, each with a fixServers
Cypress says the npm package is installed but the binary is missing
Cypress binary is missing after npm install in CI or in a Docker build
The npm package is only a launcher.
3 causes, each with a fix