Accessing Docker with non-root user privileges

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/containers/json: dial unix /var/run/docker.sock: connect: permission denied

Does this error look familiar?

What is happening is that docker client is communicating with the engine using socket file. As docker service is launched using root user and socket file is accessible to every user in “docker” group, you will not be able to connect to this file from docker client executed launched with your current user access.

2 possible solutions:

  1. Use docker with root privileges
sudo docker ps
  1. Grant your user access to the socket file by adding to the “docker” group
sudo usermod -a -G docker $USER

Publish Date: 2019-06-13