Explore Courses Blog Tutorials Interview Questions
0 votes
in DevOps and Agile by (2.3k points)

I am working with docker on my machine which runs ubuntu OS. Normally I have to type in sudo before any docker commands:

$ sudo docker run hello-world

It's a bit annoying to use sudo every time I use docker commands, Can I write commands like given below?

$ docker run hello-world
My question is, how can i write commands without sudo without getting this error ? :
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.35/containers/create: dial unix /var/run/docker.sock: connect: permission denied.See 'docker run --help'.

1 Answer

0 votes
by (6.9k points)

I think what you are looking for is running docker engine as non-root but without using root access. For this you will have to add it to docker group:

But before that you will have to create a docker group if it already does not there :

$ sudo groupadd docker

Then add the user you are using to this docker group.

$ sudo usermod -aG docker $USER

then Logout and then login again and then run docker 

$ newgrp docker

You will now be able to use docker commands without typing sudo.

Hope that helps :)

Hey looking to get more adept in docker? try a docker training course. 

Browse Categories