Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't add user to docker group

I'm trying to set docker up on a new system, and when running docker info I get:

docker -v
=> Docker version 18.09.5, build e8ff056

docker info
=> Got permission denied while trying to connect to the Docker daemon
   socket at unix:///var/run/docker.sock: Get
   http://%2Fvar%2Frun%2Fdocker.sock/v1.39/info: dial unix 
   /var/run/docker.sock: connect: permission denied

Following the docs, I've tried:

sudo usermod -a -G docker $USER

Which returns no output. When I then run groups:

groups
=> mark adm cdrom sudo dip plugdev lpadmin sambashare

I can see a docker group exists:

less /etc/group | grep docker
=> docker:x:131:mark

And can see that it owns a socket running where the error message states:

ls -la /var/run/ | grep docker
=> 
drwx------  5 root                root                 120 May 25 14:54 docker
-rw-r--r--  1 root                root                   5 May 25 14:54 docker.pid
srw-rw----  1 root                docker                 0 May 25 14:54 docker.sock

So why can't I add myself to that group with sudo usermod -a -G docker $USER ?

like image 366
Mark Avatar asked May 25 '19 14:05

Mark


2 Answers

You need to reload your shell in order to make the changes take effect. Often you need to reboot your shell process and possibly even restart your computer.

e.g

sudo usermod -aG docker $USER
sudo reboot

See @4Z4T4R answer and give a thumbs https://stackoverflow.com/a/66297855/7961500

Load changes without quitting your shell

To avoid starting a new shell you can run. (Doesn't seem to work for all environments)

exec su -l $USER

This will create a new subshell with the loaded changes and replace your current shell with it.

If nothing else is working for you.

Another way if you just need to get it working now, is to change your primary group. This is only a temp solution as with any new shell you will need to apply it again.

export my_group=$(id -gn)
newgrp docker
newgrp $my_group

Documentation

You can also look at the offical documentation here https://docs.docker.com/engine/install/linux-postinstall/

like image 130
Louis Avatar answered Oct 13 '22 06:10

Louis


In my case, on Ubuntu 20.04, run sudo reboot after this command:

$ sudo usermod -aG docker $USER

I literally needed to reboot my operating system (and machine) for the change to take effect. Restarting/reloading the bash session did not apply the new setting.

Sure, newgrp docker does the trick "on the fly" without restart/reboot/re-anything... but once the session terminates, POOF you're not in the docker group any longer.

Added this as a formal answer bc it genuinely solved the OP's---and my (identical)---problem.

Credit should go to @Omari Celestine for the suggestion, but because I suck at interpretation, I (and maybe you) need the literal disambiguation that this answer provides.

like image 20
4Z4T4R Avatar answered Oct 13 '22 08:10

4Z4T4R