I installed Docker in my machine where I have Ubuntu OS. After than I installed docker, when I run
sudo docker run hello-world
All it's ok, but I want to hide the word sudo
to make more short the command.
If I write the command without the word sudo
docker run hello-world
That display the following:
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'.
It's happened the same when I try to make
docker-compose up
How can I resolve this?
If you want to run docker as non-root user then you need to add it to the docker group.
Taken from the docker official documentation: manage-docker-as-a-non-root-user
You can always try
Manage Docker as a non-root user
paragraph in the https://docs.docker.com/install/linux/linux-postinstall/ docs.After doing this also if the problem persists then you can run the following command to solve it:
To fix that issue, I searched where is my docker and docker-compose installed. In my case,
docker
was installed in/usr/bin/docker
anddocker-compose
was installed in/usr/local/bin/docker-compose
path. Then, I write this in my terminal:To docker:
To
docker-compose
:Now I don't need write in my commands docker the word
sudo
/***********************************************************************/
ERRATA:
The best solution of this issue was commented by @mkasberg. I quote comment:
That might work, you might run into issues down the road. Also, it's a security vulnerability. You'd be better off just adding yourself to the docker group, as the docs say. sudo groupadd docker, sudo usermod -aG docker $USER.
Docs:
https://docs.docker.com/install/linux/linux-postinstall/Thanks a lot!
chmod 0777 /home/huginn/mysql-data
this is my solution.
After an upgrade I got the permission denied. Doing the steps of 'mkb' post install steps don't have change anything because my user was already in the 'docker' group; I retry-it twice any way without success.
After an search hour this following solution finaly worked :
Solution came from Olshansk.
Look like the upgrade have recreate the socket without enough permission for the 'docker' group.
Problems
This hard chmod open security hole and after each reboot, this error start again and again and you have to re-execute the above command each time. I want a solution once and for all. For that you have two problems :
1) Problem with
SystemD
: The socket will be create only with owner 'root' and group 'root'.You can check this first problem with this command :
If every this is good, you should see '
root/docker
' not 'root/root
'.2 ) Problem with graphical Login : https://superuser.com/questions/1348196/why-my-linux-account-only-belongs-to-one-group
You can check this second problem with this command :
If everything is correct you should see the docker group in the list. If not try the command
if you see then the docker group it is because of the bug.
Solutions
If you manage to to get a workaround for the graphical login, this should do the job :
But If you can't manage this bug, a not so bad solution could be this :
This work because you are in a graphical environnement and probably the only user on your computer. In both case you need a reboot (or an
sudo chmod 666 /var/run/docker.sock
)