Welcome to thatlinuxbox.com Thursday, June 04 2020 @ 03:33 PM UTC

Access Docker After Install Without Logout or Reboot

  • Tuesday, March 24 2020 @ 06:48 PM UTC
  • Contributed by:
  • Views: 109
Linux, Open Source, and Tech Stuff

Share
  • Google Plus
  • Facebook
  • Twitter
  • Reddit
  • LinkedIn
  • Digg

By default, after installing docker on Ubuntu, normal user accounts cannot connect to the docker daemon.

$ sudo apt install docker.io

$ docker ps

Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock

 

After adding one's user account to the "docker" group, a full logout and login is typically needed for the user account to receive the new group membership. And in fact, on Ubuntu running the default desktop environment, one may need to actually reboot or run an extra command such as:

$ loginctl terminate-user $USERNAME

because systemd seems to preserve a user context even after logout.

Starting a new bash login shell inside an existing terminal is definitely insufficient:

$ bash --login -i

Terminating a desktop session can be fairly inconvenient, depending on the amount of Work In Progress and document editors and browser tabs, etc.

 

On Ubuntu 18.04, here are steps to allow a normal user account to immediately access docker without having to log out first:

$ groups  # note that "docker" will not be in list of groups

$ sudo gpasswd -a $USERNAME docker   # add your specific username to the "docker" group

 

$ sudo grpck   # verify that your group file has no syntax errors, and only the expected differences exist
[sudo] password for dan: 
'dan' is a member of the 'docker' group in /etc/group but not in /etc/gshadow

$ sudo grpconv    # syncs group and gshadow aka the magic command that prevents "newgrp" from generating the error: 'failed to crypt password with previous salt'

$ newgrp docker  # log in to new group (starts a subshell with the new group membership attached, environment preserved)

$ groups  # note that "docker" will now appear in list of groups for the user

$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED
         STATUS              PORTS               NAMES

 

$ docker run docker/whalesay cowsay "No Logout Needed!"
 ___________________ 
< No Logout Needed! >
 ------------------- 
    \
     \
      \     
                    ##        .            
              ## ## ##       ==            
           ## ## ## ##      ===            
       /""""""""""""""""___/ ===        
  ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ /  ===- ~~~   
       \______ o          __/            
        \    \        __/             
          \____\______/   

 

Thanks to the following articles which provided reference for this blog post:

https://askubuntu.com/questions/477551/how-can-i-use-docker-without-sudo

https://www.geeksforgeeks.org/grpconv-command-in-linux-with-examples/

https://askubuntu.com/questions/1045993/after-adding-a-group-logoutlogin-is-not-enough-in-18-04

Access Docker After Install Without Logout or Reboot | 0 comments | Create New Account

The following comments are owned by whomever posted them. This site is not responsible for what they say.


User Functions

Login

Connect

thatlinuxbox.com is the home of Dan Stoner's Personal Blog, Photos, and More (opinions, rants, techno-babble, and possibly a few useful tidbits of knowledge).

Questions or Comments about this site? Contact danstoner _ at _ gmail.com.

RSS Feed for this blog

Other places to find me on the web:

Twitter

LinkedIn

GitHub

Support This Site

If you like something that you find on this site, please consider making a purchase through one of the links below or sending me an item from my Amazon Wish List.


The Clymb


Awesome VPS hosting by Linode.com