简体   繁体   中英

Ubuntu docker swarm error “docker: Cannot connect to the Docker daemon. Is the docker daemon running on this host?.”

I am trying to set up docker swarm with consul on some Ubuntu 14.04 vagrant boxes, however there is an issue with the docker daemon. I already have a progrium/consul container running and a swarm manager container running. 172.28.128.3 is the master machine running everything, 172.28.128.4 is the machine I am trying to start a docker swarm container on. Here is my command and the output:

vagrant@ubuntu-14:~$ docker -H=172.28.128.4:2375 run -d swarm join \
> --advertise=172.28.128.4:2375 \
> consul://172.28.128.3:8500/
docker: Cannot connect to the Docker daemon. Is the docker daemon running on this host?.
See 'docker run --help'.

There is no other problem with docker and attempting to start the daemon the same way I would on my macs boot2docker gives the following output:

vagrant@ubuntu-14:~$ eval "$(docker-machine env default)"
docker-machine: command not found

Update: here is the output of $sudo docker info and $docker info (they are exactly the same except for one line described below)

vagrant@ubuntu-14:~$ sudo docker info
Containers: 8
 Running: 2
 Paused: 0
 Stopped: 6
Images: 8
Server Version: 1.11.1
Storage Driver: aufs
 Root Dir: /var/lib/docker/aufs
 Backing Filesystem: extfs
 Dirs: 81
 Dirperm1 Supported: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins: 
 Volume: local
 Network: null host bridge
Kernel Version: 3.13.0-24-generic
Operating System: Ubuntu 14.04 LTS
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 993.9 MiB
Name: ubuntu-14
ID: BBEM:JVHD:UXV7:AGQR:ITUY:3KGT:K4RS:7KSR:ESCJ:2VZQ:QTOG:J26U
Docker Root Dir: /var/lib/docker
Debug mode (client): false
Debug mode (server): false
Registry: https://index.docker.io/v1/
WARNING: No kernel memory limit support

The only difference between the two commands is that $docker info has the following entry for Network:

 Network: host bridge null

On my second machine there is no difference at all between the two command outputs.

UPDATE: after adding DOCKER_OPTS="-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock" to the file /etc/default/docker on my worker machine and restarting the docker service on my worker server sudo docker restart swarm is working correctly. Thank you JorelC for the solution.

You have to configure all machines that You want to use docker through tcp to run in tcp mode. In Your remote machine (172.28.128.4 in your question), edit /etc/default/docker file and add something like this in DOCKER_OPTS :

DOCKER_OPTS="-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock"

After that, You need to restart the service:

sudo service docker restart

And You should use docker through tcp . Try from your client machine:

docker -H=172.28.128.4:2375 info

to test if it's working

There can also be issues if you are using clones of instances or instance images that have docker preinstalled on them.

To get around that use the following shell script:

#UNINSTALL
sudo apt-get purge -y docker-engine
sudo apt-get autoremove -y --purge docker-engine

#CLONES
sudo rm /etc/docker/key.json

#INSTALL
sudo apt-get install -y curl
sudo curl -sSL http://get.docker.com | sudo sh
sudo usermod -aG docker $(whoami)
sudo su root

And if you want to use the newest version of docker swarm (1.12 the one with docker swarm built in) use the following script:

# DOCKER 1.12.0
sudo apt-get update
sudo apt-get purge -y lxc-docker docker-engine
sudo apt-get autoremove -y --purge docker-engine
sudo curl -fsSL https://experimental.docker.com/ | sudo sh
sudo chmod 777 /etc/default/docker
echo 'DOCKER_OPTS="-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock"' > /etc/default/docker
sudo chmod 755 /etc/default/docker 
sudo rm /etc/docker/key.json
sudo service docker restart
sudo usermod -aG docker $(whoami)
sudo su root

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM