Welcome to thatlinuxbox.com Saturday, June 15 2024 @ 02:03 AM UTC

Access Docker After Install Without Logout or Reboot

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

  • 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:




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



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:




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