Run docker without sudo in ubuntu - docker

Yes I have followed steps provided here https://docs.docker.com/engine/install/ubuntu/ and https://docs.docker.com/engine/install/linux-postinstall/ and also checked this thread docker.sock permission denied
But still getting the below problem when docker is run without sudo in Ubuntu 18.04
docker run hello-world
docker: Cannot connect to the Docker daemon at unix:///run/user/1000/docker.sock. Is the docker daemon running?.
See 'docker run --help'.
It is rather frustrating as I tried multiple times.

It worked fine after deleting the below entry in .bashrc
export DOCKER_HOST=unix:///run/user/1000/docker.sock
I'm not sure how that line made it into .bashrc
Feel so stupid now. Anyway thanks!

Related

Bitnami Jenkins: Got permission denied while trying to connect to the Docker daemon socket

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.
I'm getting this whenever I try to run Docker inside Jenkins. The machine was installed using the Bitnami Jenkins image. I have exhausted every troubleshooting option I can think of in an effort to solve what should be a simple permissions issue, but keep coming up empty.
I have attempted all the suggestions here at this Stack Overflow thread. I have attempted adding jenkins, bitnami, azureuser and anyone else on the system that looks like they might run Docker to the docker group using sudo usermod -a -G docker <user>.
I can sudo su - jenkins and docker run hello-world without issues.
Yet, still, no matter what I do, I am reduced to this error.
sudo usermod -aG docker $USER does nothing.
sudo usermod -a -G docker bitnami does nothing.
sudo usermod -a -G docker jenkins does nothing.
sudo usermod -a -G docker literallyanyusericanthinkof does nothing.
Rebooted/restarted hundreds of times now, no help.
I can run Docker in literally any other context on the machine, but Jenkins still refuses to run it. I am at my whits end getting this to work. I've configured at least two other Jenkins servers to do this before, but this one is giving me grief and I have no idea why.
Can anyone point me in the right direction?
So I don't necessarily feel good about this, but I ran into this issue today and I got around it by changing the ownership on the docker.sock file in /var/run to jenkins:docker and now my Jenkins is working. The command I ran was
sudo chown jenkins:docker /var/run/docker.sock
I'm not using Jenkins, but for my personal account, my method was similar to #benjaminpazienza above. I also don't feel great about it but it works.
sudo chmod 666 /var/run/docker.sock
I ran into the same problem, Jenkins restart didn't work as well.
I found that restarting the machine hosting the Jenkins will fix it. Avoid giving r/w access to others by chmod as much as you can.

can't run docker in ubuntu 20.04

I had tried to install docker like I read in lots of site with the same steps, but it didn't work and always send me that error massage:docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?. and I didn't could find solution that work.
After that I tried to test a bit the sudo snap, and I was surprised to discover that I can install docker using sudo snap install docker and its look like it worked, but when I run the sudo docker run -dt centos bash, I had got the same error.
It's not only a issue with CentOS, I had tried this with kali, mint, ubuntu, and fedora, no one of them worked, and the error is always the same/
thanks for help.
You need to mount /var/run/docker.sock
sudo docker run -dt -v /var/run/docker.sock:/var/run/docker.sock centos bash

Docker on Ubuntu inside WSL

I want to play with hyperledger fabric and this require to have linux.
Right now I want to use Windows and my idea was to install Ubuntu with WSL and just develop inside it.
The problem apear when I want to use docker.
I follow the steps in this tutorial step by step but I run into some problem.
filip#CSGN044D:~$ docker --version
Docker version 19.03.5, build 633a0ea838
filip#CSGN044D:~$ docker run hello-world
docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'.
filip#CSGN044D:~$ sudo service docker start
* Starting Docker: docker
and again...
filip#CSGN044D:~$ docker run hello-world
docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'.
Is this even possible ?
Looks like your Docker CLI is still trying to connect to the local Unix socket instead of localhost. Make sure your DOCKER_HOST environment variable is set to tcp://localhost:2375
Try by setting it in your shell first
export DOCKER_HOST=tcp://localhost:2375
Sanity check
echo $DOCKER_HOST
Now try running all your regular Docker commands. If those work, add this to your .bashrc
echo "export DOCKER_HOST=tcp://localhost:2375" >> ~/.bashrc
source ~/.bashrc
Not that in the tutorial the author uses localhost:2375 instead of tcp://localhost:2375. I think you have to explicitly specify the protocol. Also, your shell might not be using bash_profile as the config file (Usually Mac shells use that) so try adding it to your bashrc instead.

Missing .docker folder on Ubuntu

I followed the official guide and installed docker-ce on Ubuntu 18.04 x64.
Per the instructions on Manage Docker as a non-root user, I tried to modify the ownership of .docker folder, and got a "No such file or directory" error:
$ sudo chown "$USER":"$USER" /home/"$USER"/.docker -R
chown: cannot access '/home/eric/.docker': No such file or directory
In fact, I don't even have a .docker folder:
$ ls ~/.docker
ls: cannot access '/home/eric/.docker': No such file or directory
In an earlier step, I was able to run the hello-world container successfully:
$ sudo docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
What did I do wrong?
Having the same problem. It finally worked for me after I restarted my laptop (which is running Ubuntu 18.04). Logging out and back in wasn't enough.
Manually created the .docker folder using mkdir .docker before restarting though.
The directory .docker (and the file .docker/config.json) will be created when you successfully authenticate to a Docker registry e.g Docker Hub running the command docker login.
(This presupposes $USER is part of the group docker.)

Docker - cannot connect to the Docker daemon

I'm trying to start a new Docker container with:
docker run -it ubuntu /bin/bash
However I get the following
Checking for the daemon, I get
Any idea what the problem might be?
I had the same kind of problem couple of days ago on LINUX, try below command,use on sudo mode
sudo usermod -aG docker your_user_name
OR
sudo usermod -aG docker $(whoami)
then logout and log in.:) walla
For Mac : see https://stackoverflow.com/users/1978931/dayel-ostraco
I got this problem. In my case, ps showed that the docker daemon was not running. Problem was, I had no clue why.
$ sudo docker -d
attempts to start the daemon manually and displays an error message if it fails.
In my case, my kernel was a bit old and didn't support docker.
There are lots of reason why the daemon may not start, so it's best to find out if it's running and if not, why not.

Resources