After installing docker, you may encounter that your commands fail with a “permission denied” message when trying to run them as a non-root user:
my_user@my_docker_host$ docker build -t my_image .
Got permission denied while trying to connect to the Docker daemon socket at ...
The same command succeeds when run as root, but that is nothing to write home about. Root can do anything.
Docker’s official documentation addresses this problem at:
https://docs.docker.com/engine/install/linux-postinstall/#manage-docker-as-a-non-root-user
But if you are like me, you either did not read it or you did and the forgot it … again. No problem, you need to:
- Create a docker group.
sudo groupadd docker
- Add your user to the docker group.
sudo usermod -aG docker $USER
Logout and login again, or activate the changes by typing this:
newgrp docker
IMPORTANT: If running on a virtual machine, you may have to restart the virtual machine for the changes to take effect. Yes, it’s in the official documentation, but I did not see it.