1

cannot run docker as non-privileged user. I added user to docker group with:

sudo groupadd -a -G docker $USER

I loggeg out and in again, still no success. I am running docker on a Ubuntu 21.10 system.

2
  • Please provide the output of id to check whether that actually worked. Also please provide the entire error message you get when trying to run docker run --rm -it hello-world.
    – Daniel B
    Jan 9, 2022 at 11:38
  • It worked now after I turn off and on my laptop again...Thanks for your comment!
    – t0v4
    Jan 9, 2022 at 13:11

1 Answer 1

1

When you use "sudo" you are forking a new process as "root". So the $USER variable will be "root" and not your user.

Replace the $USER by the name of the user you are trying to add privileges.

sudo groupadd -a -G docker username_here

Finally, logout and login again, start a new terminal session and run "id" to check if the user now belongs to the docker group.

2
  • No, that’s not the cause. At the time the sudo process is started, the variable $USER, which is shell-specific, has already been replaced with its value. It’s certainly true that the environment variables change, but groupadd does not use these.
    – Daniel B
    Jan 11, 2022 at 8:08
  • Thanks for the explanation Daniel. I felt this was not right in the minute that I finished writing it hahah Jan 12, 2022 at 0:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .