You tried to run a Docker command without sudo or in other words, as a non root user. This has returned an error which is similar to the following:
docker: Got permission denied while trying to connect to the Docker daemon socket at XX /var/run/docker.sock: connect: permission denied.
This ‘permission denied‘ error has been returned because you do not have sufficient privileges on the file /var/run/docker.sock .
Since the Unix socket belongs to the user root, what you can do is obviously to run the command as sudo since you will then have all root privileges.
What you can also do in order to run the command as a non root user is to add a docker group and then add your user to it. This can be done using the command :
sudo groupadd docker
After having added the docker group and in order to get group policies applied correctly, you would need to exit and log in again.
To validate the changes to groups, you also have the possibility to run the command below in case you are on Ubuntu or Linux in general :
Now to check if, without root, docker can be run, invoke the command below:
docker run hello-world
If you still get an error, you may need to reboot by running the command :
Source : For more details on this, you may want to refer to the official documentation of Docker.
If you like the content, we would appreciate your support by buying us a coffee. Thank you so much for your visit and support.