Using Docker as non-root

[UPDATE 2020-04-21] as mentioned in this post it’s not needed anymore:

Good news: the new docker (version 19.03 (currently experimental)) will be able to run rootless negating the problems that can occur using a root user. No more messing with elevated permissions, root and anything that might open up your machine when you did not want to.

Normally you need to run docker as root:

sudo docker run hello-world

If this is going on your nerves, you can add your normal user to the docker-usergroup.
But before you do this, read the warning in this post (where i also got the code from)

sudo groupadd docker
sudo gpasswd -a $USER docker

logout / logout from your computer and run:

docker run hello-world

It should work now!

If you got something like

docker run hello-world
WARNING: Error loading config file: /home/YOURUSERNAME/.docker/config.json - stat /home/YOURUSERNAME/.docker/config.json: permission denied

This can be fixed by typing in this post

sudo chown "$USER":"$USER" /home/"$USER"/.docker -R
sudo chmod g+rwx "/home/$USER/.docker" -R