Docker command can't connect to Docker daemon
Solution 1
You need to add your current user to the docker group as follows:
sudo usermod -aG docker $(whoami)
then logout & login again into the system or restart the system.
test by docker version
for further info how to install docker-engine follow docker documentation
Solution 2
Add the user to the docker group
-
Add the docker group if it doesn't already exist:
sudo groupadd docker
-
Add the connected user "${USER}" to the docker group:
sudo gpasswd -a ${USER} docker
-
Restart the Docker daemon:
sudo service docker restart
Either do a
newgrp docker
or log out/in to activate the changes to groups.
Solution 3
Usually, the following command does the trick:
sudo service docker restart
This, instead of docker start
for the cases where Docker seems to already be running.
If that works then, as suggested and in another answer and on this GitHub issue, if you haven't added yourself in the docker group do it by running:
sudo usermod -aG docker <your-username>
And you're most likely good to go.
As for anybody else bumping into this, in some OS's docker doesn't start right after you install it and, as a result, the same can't connect to daemon message
appears. In this case you can first verify that Docker is indeed not running by checking the status of your docker service by executing:
sudo service docker status
If the output looks something like: docker stop/waiting
instead of docker start/running, process 15378
then it obviously means Docker is not active. In this case make sure you start it with:
sudo service docker start
And, as before, you'll most likely be good to go.
Solution 4
note to self: I get the error from the question's title when I forget to run docker
command with sudo
:
sudo docker run ...
[Ubuntu 15.10]
Solution 5
Had the same issue and what worked for me was:
Checking the ownership of /var/run/docker.sock
ls -l /var/run/docker.sock
If you're not the owner then change ownership with the command
sudo chown *your-username* /var/run/docker.sock
Then you can go ahead and try executing the docker commands hassle-free :D
Related videos on Youtube
kramer65
Updated on July 08, 2022Comments
-
kramer65 almost 2 years
I want to make a move to Docker, so I've just started to mess around with it. I've installed Docker on a VirtualBox Ubuntu 15.10 (Wily Werewolf) installation and as suggested here I then tried running a basic nginx Docker image:
$ docker run --name mynginx1 -P -d nginx Cannot connect to the Docker daemon. Is the docker daemon running on this host?
So I checked out whether Docker was running:
$ sudo service docker status ● docker.service - Docker Application Container Engine Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled) Active: active (running) since vr 2015-11-06 08:41:48 CET; 15min ago Docs: https://docs.docker.com Main PID: 7542 (docker) CGroup: /system.slice/docker.service └─7542 /usr/bin/docker daemon -H fd:// nov 06 08:41:47 kramer65-VirtualBox systemd[1]: Starting Docker Application Container Engine... nov 06 08:41:47 kramer65-VirtualBox docker[7542]: time="2015-11-06T08:41:47.900410966+01:00" level=info msg="API ...ock" nov 06 08:41:48 kramer65-VirtualBox docker[7542]: time="2015-11-06T08:41:48.033514149+01:00" level=info msg="Fire...lse" nov 06 08:41:48 kramer65-VirtualBox docker[7542]: time="2015-11-06T08:41:48.141594321+01:00" level=info msg="Defa...ess" nov 06 08:41:48 kramer65-VirtualBox docker[7542]: time="2015-11-06T08:41:48.416294436+01:00" level=warning msg="Y...it." nov 06 08:41:48 kramer65-VirtualBox docker[7542]: time="2015-11-06T08:41:48.565507576+01:00" level=info msg="Load...rt." nov 06 08:41:48 kramer65-VirtualBox docker[7542]: time="2015-11-06T08:41:48.567907022+01:00" level=info msg="Load...ne." nov 06 08:41:48 kramer65-VirtualBox docker[7542]: time="2015-11-06T08:41:48.567945214+01:00" level=info msg="Daem...ion" nov 06 08:41:48 kramer65-VirtualBox docker[7542]: time="2015-11-06T08:41:48.567969891+01:00" level=info msg="Dock....9.0 nov 06 08:41:48 kramer65-VirtualBox systemd[1]: Started Docker Application Container Engine. Hint: Some lines were ellipsized, use -l to show in full.
This suggests that the Docker daemon is actually already running, but to be sure I just started the Docker daemon manually:
$ sudo docker daemon INFO[0000] API listen on /var/run/docker.sock INFO[0000] [graphdriver] using prior storage driver "aufs" INFO[0000] Firewalld running: false INFO[0000] Default bridge (docker0) is assigned with an IP address XXX.XX.X.X/XX. Daemon option --bip can be used to set a preferred IP address WARN[0000] Your kernel does not support swap memory limit. INFO[0000] Loading containers: start. INFO[0000] Loading containers: done. INFO[0000] Daemon has completed initialization INFO[0000] Docker daemon commit=76d6bc9 execdriver=native-0.2 graphdriver=aufs version=1.9.0
I then tried running the image again, but with the same result:
$ docker run --name mynginx1 -P -d nginx Cannot connect to the Docker daemon. Is the docker daemon running on this host?
I tried sudo'ing the command, but to no avail. What am I doing wrong here?
-
Daniel Loureiro over 8 yearssame problem. I'm on Ubuntu 15.10 too :(
-
Lucas Tettamanti over 8 yearssame problem, ubuntu 15.10
-
Nasruddin over 8 yearsJust restart your docker service that's all. Thanks @jim <pre>sudo service docker restart</pre>
-
Rafael_Espericueta almost 8 yearsNasruddin, that sure did NOT work for me... :-(
-
romaroma over 7 yearsI had to restart the machine to make it work.
-
muon over 7 yearsI have to use
sudo
even after adding user -
Eugen Konkov over 7 yearsPossible duplicate of Docker can't connect to docker daemon
-
Elaine almost 7 yearsI got this error with Azure Container Service master machine, and failed to fix this by any solution provided here, a one-click restart resolved this :(
-
-
Alar over 8 yearsthat "wget" thing just put the docker repository in your apt source....i.e. the same thing you are asked to manually do in the "correct and official way"....
-
Daniel Loureiro over 8 yearsI'm afraid you are wrong, Alar. The "wget" method will add docker repository in your apt source, which is good, but it will also do many other bad things like set a DOCKER_HOST env var, which will prevent docker to run out-of-the-box. Is not because both methods add docker to the repo that they are both the same.
-
benka over 8 yearssilly but it worked for me too @RobinLoxley, this should be an actual answer not just a comment, let me know if you post it, i'll give you an upvote ;)
-
johntellsall about 8 yearsStep 2 can be simplified as:
sudo usermod -aG docker $USER
-
Michele about 8 yearsI would underline "logout & login again into the system or restart the system"
-
RhinoDevel about 8 years"I tried sudo'ing the command, but to no avail. Does anybody know what I'm doing wrong here? All tips are welcome!"
-
brandizzi about 8 years@Junaid answer below shows how to avoid the logout/login step, in case you are, like me, so lazy you don't want to restart your apps ;)
-
basic6 about 8 yearsOn Fedora 23, this group may be called
dockerroot
. Also, you probably want to install it from the repository (instead ofcurl ... | sh
) so it can be updated later:dnf install docker
-
bergey about 8 yearsIt seems that
newgrp docker
is local to the shell, not the login session. This is not at all clear from the man page. -
TonyTony almost 8 yearsmany do not have a group "docker", so we have to add it first
groupadd docker
and then add it to your usernamesudo usermod -aG docker your_username
-
aalaap almost 8 yearsThis is exactly what's mentioned in the Docker tutorial, but logging out and back in again didn't work for me. I had to restart the system to get it working.
-
Apokai almost 8 yearsWorked for me. Thanks!
-
ghanbari almost 8 yearsI see docker version information, but in the end of output, i see
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
-
Zhang LongQI almost 8 yearsThis is required if you only logout and login.
-
buhtz over 7 yearsPlease format this as code! And explain this command. And use the long (starting with
--
) versions of options. -
yarin over 7 yearsWorks for vagrant machine as well
-
gerrit_hoekstra about 7 yearsAfter exhausting all the other possibilities, this is what got it to work on Sabayon/Gentoo Linux for me.
-
Meghna Natraj over 6 yearsThe only answer that worked! On a private cloud Linux machine, and it still worked!
-
chris over 6 yearsOn CentOS 7 this group is called
dockerroot
, and I also had to add"group": "dockerroot"
to/etc/docker/daemon.json
to ensure that my user could access thedocker.sock
file. -
Abhinav Manchanda over 6 yearsJust to add here, if you're using AWS, you'll need to reboot the EC2 instance.
-
Kshitij Saraogi almost 5 yearsWorked on Ubuntu 18.04! Thanks
-
Lucas Bustamante almost 5 yearsThat file is owned by
root
but indocker
group. The correct approach is to assign your current user to thedocker
group, according to Docker's documentation:sudo groupadd docker && sudo usermod -aG docker $USER
-
therobyouknow over 4 years@Federico - "no need to log out, use:
exec su -l $USER
" - thank you +1 -
ashishSober almost 3 years/var/run# service docker status [FAIL] Docker is not running ... failed!