Fix Got permission denied while trying to connect to the Docker

I hit so many times this issue that I’m nearly sure you too! Bookmark this page because in this article we are going to fix the Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock:

I have a freshly installed docker in Ubuntu 20.04 LTS and straight after the installation I run

$ sudo snap install docker
docker 20.10.14 from Canonical✓ installed
d3@my-local-k3s:~$ docker ps
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.24/containers/json": dial unix /var/run/docker.sock: connect: permission denied

So to fix got permission denied you just need to run these 2 commands

$ sudo groupadd docker
$ sudo usermod -aG docker ${USER}

Reboot your machine (newgrp will not work with ubuntu 20) and login again

$ docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

Job done!

Help us grow by sharing this article

d3

d3 is an experienced Software Engineer/Developer/Architect/Thinker with a demonstrated history of working in the information technology and services industry. Really passionate about technology, programming languages and problem solving. He doesn't like too much the self celebration and prefers to use that time doing something useful ...i.e. coding

You may also like...