0

I have Ubuntu 18.04. and after installing docker i added my user to docker group with the command

sudo usermod -aG docker ${USER} 

and logged in

su - ${USER} 

and if I check id, my user is added to docker group.

But when I reopen the terminal i cant do docker commands without sudo unless i explicitly do su ${USER}

also, I can't find docker group with the default user. What am I missing here?

3
  • 2
    only do a restart. Commented Nov 19, 2018 at 11:47
  • 4
    Changes to group credentials don't affect your current session. You just need to log out and log back in; it's not necessary to restart. Commented Nov 19, 2018 at 12:31
  • 1
    yup! Thanks, it worked. Log out and log in. P.S. why is it necessary? Commented Nov 19, 2018 at 13:10

1 Answer 1

1

@larsks already replied to the main question in a comment, however I would like to elaborate on the implications of that change (adding your default user to the docker group).

Basically, the Docker daemon socket is owned by root:docker, so in order to use the Docker CLI commands, you need either to be in the docker group, or to prepend all docker commands by sudo.

As indicated in the documentation of Docker, it is risky to follow the first solution on your personal workstation, because this just amounts to providing the default user with root permissions without sudo-like password prompt protection. Indeed, users in the docker group are de facto root on the host. See for example this article and that one.

Instead, you may want to follow the second solution, which can be somewhat simplified by adding to your ~/.bashrc file an alias such as:

alias docker="sudo /usr/bin/docker" 

Thus, docker run --rm -it debian will be automatically expanded to sudo /usr/bin/docker run --rm -it debian, thereby preserving sudo’s protection for your default user.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.