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
I solve this error with the command :
$ sudo chmod 666 /var/run/docker.sock
you can follow these steps and this will work for you:
sudo groupadd docker
sudo usermod -aG docker $USER
groups
newgrp docker
sudo chown root:docker /var/run/docker.sock
sudo chown "$USER":"$USER" /home/"$USER"/.docker -R
sudo chmod g+rwx "$HOME/.docker" -R
After that test you can run docker ps -a
To access the super user or root user, follow:
At user@computer:
$sudo su
After you enter your password, you'll be at root@computer:
$docker run hello-world
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.40/images/json: dial unix /var/run/docker.sock: connect: permission denied
sudo chmod 666 /var/run/docker.sock
This fix my problem.
To fix that issue, I searched where is my docker and docker-compose installed. In my case, docker
was installed in /usr/bin/docker
and docker-compose
was installed in /usr/local/bin/docker-compose
path. Then, I write this in my terminal:
To docker:
sudo chmod +x /usr/bin/docker
To docker-compose
:
sudo chmod +x /usr/local/bin/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!
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:
sudo chmod 666 /var/run/docker.sock