If you're getting permission denied errors when running Docker commands, it's likely because your user isn't in the docker group.
When you install Docker, it creates a Unix socket that only the root user and users in the docker group can access. If your user isn't in this group, you'll see errors like:
docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/create": dial unix /var/run/docker.sock: connect: permission denied.
Add your user to the docker group:
sudo usermod -aG docker $USER
⚠️ Warning: Adding a user to the docker group is equivalent to giving them root access. Only do this on trusted systems.
After running the command, you'll need to log out and back in for the group membership to take effect. Alternatively, you can run:
newgrp docker
Test with a simple command:
docker run hello-world
If it works, you're all set!
If you're still having issues:
sudo systemctl start dockergroups $USERIf you don't want to add your user to the docker group, you can prefix all docker commands with sudo:
sudo docker run hello-world
But this gets tedious quickly.