In this post I will show you about how to use Docker without using sudo command.
by the way, these are errors you may have if you run Docker commands without enough permission access:
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.26/containers/json: dial unix /var/run/docker.sock: connect: permission denied
or an error like this:
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.26/containers/create: dial unix /var/run/docker.sock: connect: permission denied.
See ‘docker run –help’.
Snapshot of docker permission Errors :
To fix this kind of issue is fairly easy, you just need to add your user to docker group so your current user account will have access to the docker command, here is step by step instruction to add your user to docker group:
- Make sure that your docker service is running
sudo /etc/init.d/docker status
- Create new docker group (in case the previous one is not exist)
sudo groupadd docker
groupadd: group ‘docker’ already exists
- add your current logged in user t the docker group
sudo usermod -aG docker $USER
- Restart docker daemon / service
sudo service docker restart
- re-login your current user
- That’s all, have fun…