Search code examples
dockervagrantubuntu-14.04consuldocker-swarm

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.


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