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

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

2 Likes

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.

8 Likes

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

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

10 Likes

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

Thank you

1 Like

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

1 Like

Thanks, same as suggested,

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

thanks a lot, that’s helpful

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

and then will making relogin in system

5 Likes

Thank you. This was exactly my problem on ubuntu.

thanks, this solved my problem

thanks for saving my day!

:persevere:

Thanks you @programmerq

Thank you @programmerq

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.

5 Likes

@decomads - Ur the man! Thanks

1 Like

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

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.

1 Like