Docker Community Forums

Share and learn in the Docker community.

Cannot connect to the Docker daemon. Is the docker daemon running on this host?


(Dnewton) #1

Now I am able to get primary manager up

Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: swarm/1.2.0
Role: primary
Strategy: spread
Filters: health, port, dependency, affinity, constraint

However when trying to join the cluster, the node0 would complain Cannot connect to the Docker daemon. Is the docker daemon running on this host?

The command used to connect to the cluster is

docker run -d dockerswarm/swarm:master join --advertise=192.168.1.105:2375 consul://192.168.1.103:8500

And the swarm info says

Filters: health, port, dependency, affinity, constraint
Nodes: 1
(unknown): 192.168.1.105:2375
└ Status: Pending
└ Containers: 0
└ Reserved CPUs: 0 / 0
└ Reserved Memory: 0 B / 0 B
└ Labels:
└ Error: Cannot connect to the Docker daemon. Is the docker daemon running on this host?
└ UpdatedAt: 2016-04-12T08:18:59Z
└ ServerVersion:

Log to the node0 container, netstat -tulp show no port is opened at 2375; but the process is running via ps -ef

1 root 0:00 swarm join --advertise=192.168.1.105:2375 consul://192.16…

Also changing the join command where advertise ip to container’s (172.17.0.2) doesn’t work as well.

What is the right command to join the swarm cluster from node container?

Thanks


Docker swarm node unknown
(Jeff Anderson) #2

maybe try running it as sudo docker ... instead of docker .... The user that you are running as may not have permissions to talk to /var/run/docker.sock on that system.


(Dvohra) #3

Cannot connect to the Docker daemon. Is the docker daemon running on this host?

Either run command as root
su -l root

Or run as sudo

sudo docker run -d dockerswarm/swarm:master join --advertise=192.168.1.105:2375 consul://192.168.1.103:8500


(Decomads) #4

You need to start the daemon with a separate command:
I got this from https://www.upcloud.com/support/how-to-configure-docker-swarm :

After the installation finishes, Docker usually starts up on its own, but for the next part to work you will need to stop it.
sudo service docker stop
Then run the daemon with the following command:
sudo nohup docker daemon -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock &
The script leaves the daemon running in the background, and with the Docker ready you can test that it is accepting commands.
sudo docker info
To make working with Docker easier, you should add your username to
the Docker users group. Adding a user to the group can be done with the
command underneath by replacing the with your username.
sudo usermod -aG docker


(Qzx02361) #5

Thank you, Mr decomads.
This troubleing , me too.
Your advices very very exactly!

Thank you


(Nhantdng) #6

I got the same error when running “docker commit”. The cause is I did not run it under sudo “sudo docker commit”.


(Dvohra) #7

Thanks, same as suggested,


(Cscetbon) #8

Works with sudo. Is there a way to do it without using sudo ? I tried to change /var/run/docker.sock permissions but it doesn’t work. It’s also weird because it references a file that is owned by my user :confused:

lrwxrwxrwx 1 root daemon 58 Sep 3 23:14 /var/run/docker.sock -> /Users/cyril/Library/Containers/com.docker.docker/Data/s60


(Killover) #9

thanks a lot, that’s helpful


(Nkazakov) #10

Add user in docker group
sudo usermod -aG docker $USER

and then will making relogin in system


(Adziedzi) #11

Thank you. This was exactly my problem on ubuntu.


(Thanhpk) #12

thanks, this solved my problem


(Soosap) #13

thanks for saving my day!


(Dwp20017) #14

:persevere:


(Bendenia Mhamed) #15

Thanks you @programmerq


(umesh0910) #16

Thank you @programmerq


(2n3055s) #17

For Ubuntu 16.04

Inside file /lib/systemd/system/docker.service change:
ExecStart=/usr/bin/dockerd fd://
with
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375

Inside file /etc/init.d/docker change:
DOCKER_OPTS=
with
DOCKER_OPTS="-H tcp://0.0.0.0:2375"

and then restart your computer.


(Rkrishnamurthy) #18

@decomads - Ur the man! Thanks


(MingCHEN) #19

Probably, you should set the DNS server in daemon.json, located in /etc/docker/daemon.json.

TOTALLY, you need 3 steps:
(1) check your dns server you’re using;
(2) then, set dns server in daemon.json;
(3) finnaly, restart docker service.

For more details about the steps you can look through my reply in the bottom fo this post https://forums.docker.com/t/communication-between-containers-and-wider-world/24295/8


(Amitvashist7) #20

Would like to share the my experience, I had also encounter the same error while jenkins trigger build jobs, in order to overcome this issue tried the below mentioned solutions & its work for me.

Error:
====>
[docker-jenkins-job] $ /bin/sh -xe /tmp/hudson2951930380198129000.sh
++ /usr/bin/docker ps -aq --filter ancestor=myapache_image
Cannot connect to the Docker daemon. Is the docker daemon running on this host?

  • /usr/bin/docker stop
    docker: “stop” requires a minimum of 1 argument.
    See ‘/usr/bin/docker-current stop --help’.

Solution:
=======>
Docker & Jenkins Issue
==================>

sudo gpasswd -a jenkins docker

Edit the following file : vi /usr/lib/systemd/system/docker.service

And edit this rule to expose the API : ExecStart=/usr/bin/docker daemon -H unix:// -H tcp://localhost:2375

Now it’s time to reload and restart your Docker daemon:

systemctl daemon-reload
systemctl restart docker

Then I restarted jenkins and I was able to perform docker commands as jenkins user in my jenkins jobs

sudo service jenkins restart

Results:
======>
[docker-jenkins-job] $ /bin/sh -xe /tmp/hudson6409609007865461459.sh
++ /usr/bin/docker ps -aq --filter ancestor=myapache_image

  • /usr/bin/docker rm -f 86ed79e70f88
    86ed79e70f88
    [docker-jenkins-job] $ /bin/sh -xe /tmp/hudson3750921594572949914.sh
  • /usr/bin/docker build -t myapache_image .
    Sending build context to Docker daemon 60.93 kB

Step 1 : FROM ubuntu:latest
—> 104bec311bcd
Step 2 : MAINTAINER Amit Vashist amitvashist7@gmail.com

It work’s.