hashicorp / docker-consul

Official Docker images for Consul.
Mozilla Public License 2.0
398 stars 238 forks source link

Development examples aren't working on Docker for Mac #53

Open chiefy opened 7 years ago

chiefy commented 7 years ago
❯ uname -a && docker -v
Darwin 15.6.0 Darwin Kernel Version 15.6.0: Mon Aug 29 20:21:34 PDT 2016; root:xnu-3248.60.11~1/RELEASE_X86_64 x86_64
Docker version 1.13.1, build 092cba3
❯ docker run -d --name=dev-consul consul
0f3919f4a5c72a18fd23808703d62c71d8aa30badb2ba663e3c3fa926c0d3f4e

❯ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                                                  NAMES
0f3919f4a5c7        consul              "docker-entrypoint..."   5 seconds ago       Up 3 seconds        8300-8302/tcp, 8400/tcp, 8500/tcp, 8301-8302/udp, 8600/tcp, 8600/udp   dev-consul
❯ docker logs 0f3919f4a5c7
==> Starting Consul agent...
==> Starting Consul agent RPC...
==> Consul agent running!
           Version: 'v0.7.5'
           Node ID: '42144b13-15ae-4f76-94e0-2cb7d2abef8a'
         Node name: '0f3919f4a5c7'
        Datacenter: 'dc1'
            Server: true (bootstrap: false)
       Client Addr: 0.0.0.0 (HTTP: 8500, HTTPS: -1, DNS: 8600, RPC: 8400)
      Cluster Addr: 127.0.0.1 (LAN: 8301, WAN: 8302)
    Gossip encrypt: false, RPC-TLS: false, TLS-Incoming: false
             Atlas: <disabled>

==> Log data will now stream in as it occurs:

    2017/03/01 19:47:34 [DEBUG] Using unique ID "42144b13-15ae-4f76-94e0-2cb7d2abef8a" from host as node ID
    2017/03/01 19:47:34 [INFO] raft: Initial configuration (index=1): [{Suffrage:Voter ID:127.0.0.1:8300 Address:127.0.0.1:8300}]
    2017/03/01 19:47:34 [INFO] raft: Node at 127.0.0.1:8300 [Follower] entering Follower state (Leader: "")
    2017/03/01 19:47:34 [INFO] serf: EventMemberJoin: 0f3919f4a5c7 127.0.0.1
    2017/03/01 19:47:34 [INFO] consul: Adding LAN server 0f3919f4a5c7 (Addr: tcp/127.0.0.1:8300) (DC: dc1)
    2017/03/01 19:47:34 [INFO] serf: EventMemberJoin: 0f3919f4a5c7.dc1 127.0.0.1
    2017/03/01 19:47:34 [INFO] consul: Adding WAN server 0f3919f4a5c7.dc1 (Addr: tcp/127.0.0.1:8300) (DC: dc1)
    2017/03/01 19:47:41 [ERR] agent: failed to sync remote state: No cluster leader
    2017/03/01 19:47:42 [WARN] raft: Heartbeat timeout from "" reached, starting election
    2017/03/01 19:47:42 [INFO] raft: Node at 127.0.0.1:8300 [Candidate] entering Candidate state in term 2
    2017/03/01 19:47:42 [DEBUG] raft: Votes needed: 1
    2017/03/01 19:47:42 [DEBUG] raft: Vote granted from 127.0.0.1:8300 in term 2. Tally: 1
    2017/03/01 19:47:42 [INFO] raft: Election won. Tally: 1
    2017/03/01 19:47:42 [INFO] raft: Node at 127.0.0.1:8300 [Leader] entering Leader state
    2017/03/01 19:47:42 [INFO] consul: cluster leadership acquired
    2017/03/01 19:47:42 [DEBUG] consul: reset tombstone GC to index 3
    2017/03/01 19:47:42 [INFO] consul: member '0f3919f4a5c7' joined, marking health alive
    2017/03/01 19:47:42 [INFO] consul: New leader elected: 0f3919f4a5c7
    2017/03/01 19:47:44 [INFO] agent: Synced service 'consul'
    2017/03/01 19:47:44 [DEBUG] agent: Node info in sync
==> Failed to check for updates: Get https://checkpoint-api.hashicorp.com/v1/check/consul?arch=amd64&os=linux&signature=&version=0.7.5: x509: certificate signed by unknown authority
  "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "173125c66a565b1c772c7748c201ee5e95b6445ffa060d666ca92486bf605c46",
                    "EndpointID": "228ca883b38f3d23f3135d639b578f3f5c7b6993e6dacb56f99dcb48cebb30f8",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.2",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:11:00:02"
                }
            }
❯ docker run -d consul agent -dev -join=172.17.0.2
6a736806a0b4e0659fbd472d8d6e614db3f8ef740954e8057691bb04b1fef169

❯ docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                     PORTS                                                                  NAMES
6a736806a0b4        consul              "docker-entrypoint..."   7 seconds ago       Exited (1) 5 seconds ago                                                                          amazing_haibt
0f3919f4a5c7        consul              "docker-entrypoint..."   2 minutes ago       Up 2 minutes               8300-8302/tcp, 8400/tcp, 8500/tcp, 8301-8302/udp, 8600/tcp, 8600/udp   dev-consul

❯ docker logs 6a736806a0b4
==> Starting Consul agent...
==> Starting Consul agent RPC...
==> Joining cluster...
==> 1 error(s) occurred:

* Failed to join 172.17.0.2: dial tcp 172.17.0.2:8301: getsockopt: connection refused
chugh-rahul commented 7 years ago

Is there a solution for this?

chiefy commented 7 years ago

@chugh-rahul this is probably not the best way, but here's my docker-compose orchestration to get a server running alongside three agents...

version: '2'
services:

  consul-server:
    image: dockertr.es.ad.adp.com/public/consul:0.7.1
    ports:
      - "8500:8500"
    command: agent -server -ui -bind=172.19.0.2 -client=172.19.0.2 -bootstrap-expect=1
    networks:
      consul_tmp:
        ipv4_address: 172.19.0.2

  consul-agent-1:
    image: dockertr.es.ad.adp.com/public/consul:0.7.1
    restart: always
    command: agent -join=172.19.0.2 -client=172.19.0.3
    networks:
      consul_tmp:
        ipv4_address: 172.19.0.3

  consul-agent-2:
    image: dockertr.es.ad.adp.com/public/consul:0.7.1
    restart: always
    command: agent -join=172.19.0.2 -client=172.19.0.4
    networks:
      consul_tmp:
        ipv4_address: 172.19.0.4

  consul-agent-3:
    image: dockertr.es.ad.adp.com/public/consul:0.7.1
    restart: always
    command: agent -join=172.19.0.2 -client=172.19.0.5
    networks:
      consul_tmp:
        ipv4_address: 172.19.0.5

networks:
  consul_tmp:
    driver: bridge
cleardevice commented 7 years ago

Example with docker image v0.6.4 works fine

tveon commented 7 years ago

Not working in docker-machine (on macOS) either:

$ docker-machine -v && docker -v 
docker-machine version 0.8.0, build b85aac1
Docker version 1.12.0, build 8eab29e
jwermuth commented 7 years ago

This does not work for me either. On version: Docker version 17.05.0-ce, build 89658be When I run:

docker run -d --name=dev-consul consul
docker run --name agent1 -d consul agent -dev -join=172.17.0.2
docker logs agent1

I get output

==> Starting Consul agent...
==> Joining cluster...
==> 1 error(s) occurred:

* Failed to join 172.17.0.2: dial tcp 172.17.0.2:8301: getsockopt: connection refused
TheHob commented 7 years ago

I duplicated the issue on Mac. Will try the workaround.

junglie85 commented 7 years ago

I'm having this issue on macOS too, with build 0.8.5.

docker version
Client:
 Version:      17.06.0-ce
 API version:  1.30
 Go version:   go1.8.3
 Git commit:   02c1d87
 Built:        Fri Jun 23 21:31:53 2017
 OS/Arch:      darwin/amd64

Server:
 Version:      17.06.0-ce
 API version:  1.30 (minimum version 1.12)
 Go version:   go1.8.3
 Git commit:   02c1d87
 Built:        Fri Jun 23 21:51:55 2017
 OS/Arch:      linux/amd64
 Experimental: true

The docker compose file solution works. Out of interest, what is the -bind option in the command? I can't find it referenced in the version 2 file reference.

junglie85 commented 7 years ago

It's not just macOS I have this problem on, I get it with Ubuntu too:

$ uname -a && docker -v
Linux dev 4.10.0-26-generic #30-Ubuntu SMP Tue Jun 27 09:30:12 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
Docker version 17.06.0-ce, build 02c1d87
$ docker run -d --name=dev-consul consul
43247e55be1ac1235252eedbfa37cc412ed6c10973dc053931f3be3f864dad5d
$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                                        NAMES
43247e55be1a        consul              "docker-entrypoint..."   3 seconds ago       Up 2 seconds        8300-8302/tcp, 8500/tcp, 8301-8302/udp, 8600/tcp, 8600/udp   dev-consul
$ docker inspect dev-consul | grep IPAddress
            "SecondaryIPAddresses": null,
            "IPAddress": "172.17.0.2",
                    "IPAddress": "172.17.0.2",
$ docker run -d consul agent -dev -join=172.17.0.2
a44961aa65405a589c57c12dee2e6f5089c1fa11f77ca64be27920a010054d65
$ docker run -d consul agent -dev -join=172.17.0.2
4cbd2ba573526a5c478c6693ed5c3c164b198b4e42482d51df29754c5120d460
$ docker exec -t dev-consul consul members
Node          Address         Status  Type    Build  Protocol  DC
43247e55be1a  127.0.0.1:8301  alive   server  0.8.5  2         dc1
$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                                        NAMES
43247e55be1a        consul              "docker-entrypoint..."   46 seconds ago      Up 46 seconds       8300-8302/tcp, 8500/tcp, 8301-8302/udp, 8600/tcp, 8600/udp   dev-consul
$ docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS                                                        NAMES
4cbd2ba57352        consul              "docker-entrypoint..."   20 seconds ago      Exited (1) 19 seconds ago                                                                practical_mestorf
a44961aa6540        consul              "docker-entrypoint..."   22 seconds ago      Exited (1) 21 seconds ago                                                                competent_liskov
43247e55be1a        consul              "docker-entrypoint..."   51 seconds ago      Up 50 seconds               8300-8302/tcp, 8500/tcp, 8301-8302/udp, 8600/tcp, 8600/udp   dev-consul
$ docker logs practical_mestorf 
==> Starting Consul agent...
==> Joining cluster...
==> 1 error(s) occurred:

* Failed to join 172.17.0.2: dial tcp 172.17.0.2:8301: getsockopt: connection refused
$ docker logs competent_liskov 
==> Starting Consul agent...
==> Joining cluster...
==> 1 error(s) occurred:

* Failed to join 172.17.0.2: dial tcp 172.17.0.2:8301: getsockopt: connection refused
$ docker logs dev-consul 
==> Starting Consul agent...
==> Consul agent running!
           Version: 'v0.8.5'
           Node ID: 'e4509b0e-f883-f671-6201-9249d69108bf'
         Node name: '43247e55be1a'
        Datacenter: 'dc1'
            Server: true (bootstrap: false)
       Client Addr: 0.0.0.0 (HTTP: 8500, HTTPS: -1, DNS: 8600)
      Cluster Addr: 127.0.0.1 (LAN: 8301, WAN: 8302)
    Gossip encrypt: false, RPC-TLS: false, TLS-Incoming: false

==> Log data will now stream in as it occurs:

    2017/07/01 06:51:25 [DEBUG] Using random ID "e4509b0e-f883-f671-6201-9249d69108bf" as node ID
    2017/07/01 06:51:25 [INFO] raft: Initial configuration (index=1): [{Suffrage:Voter ID:127.0.0.1:8300 Address:127.0.0.1:8300}]
    2017/07/01 06:51:25 [INFO] raft: Node at 127.0.0.1:8300 [Follower] entering Follower state (Leader: "")
    2017/07/01 06:51:25 [INFO] serf: EventMemberJoin: 43247e55be1a 127.0.0.1
    2017/07/01 06:51:25 [INFO] consul: Adding LAN server 43247e55be1a (Addr: tcp/127.0.0.1:8300) (DC: dc1)
    2017/07/01 06:51:25 [INFO] serf: EventMemberJoin: 43247e55be1a.dc1 127.0.0.1
    2017/07/01 06:51:25 [INFO] agent: Started DNS server 0.0.0.0:8600 (udp)
    2017/07/01 06:51:25 [INFO] consul: Handled member-join event for server "43247e55be1a.dc1" in area "wan"
    2017/07/01 06:51:25 [INFO] agent: Started DNS server 0.0.0.0:8600 (tcp)
    2017/07/01 06:51:25 [INFO] agent: Started HTTP server on [::]:8500
    2017/07/01 06:51:25 [WARN] raft: Heartbeat timeout from "" reached, starting election
    2017/07/01 06:51:25 [INFO] raft: Node at 127.0.0.1:8300 [Candidate] entering Candidate state in term 2
    2017/07/01 06:51:25 [DEBUG] raft: Votes needed: 1
    2017/07/01 06:51:25 [DEBUG] raft: Vote granted from 127.0.0.1:8300 in term 2. Tally: 1
    2017/07/01 06:51:25 [INFO] raft: Election won. Tally: 1
    2017/07/01 06:51:25 [INFO] raft: Node at 127.0.0.1:8300 [Leader] entering Leader state
    2017/07/01 06:51:25 [INFO] consul: cluster leadership acquired
    2017/07/01 06:51:25 [DEBUG] consul: reset tombstone GC to index 3
    2017/07/01 06:51:25 [INFO] consul: member '43247e55be1a' joined, marking health alive
    2017/07/01 06:51:25 [INFO] consul: New leader elected: 43247e55be1a
    2017/07/01 06:51:26 [INFO] agent: Synced service 'consul'
    2017/07/01 06:51:26 [DEBUG] agent: Node info in sync
    2017/07/01 06:52:08 [DEBUG] http: Request GET /v1/agent/members (235.968µs) from=127.0.0.1:57646
adalga commented 7 years ago

Any solution? I have same issue on Ubuntu 16.04

docker logs goofy_dijkstra ==> Starting Consul agent... ==> Joining cluster... ==> 1 error(s) occurred:

ronycohen commented 7 years ago

Hello, Same same here :

2017-07-11T09:55:55.067218300Z * Failed to join 172.17.0.2: dial tcp 172.17.0.2:8301: getsockopt: connection refused

on Windows 10 $ docker-machine -v && docker -v docker-machine version 0.12.0, build 45c69ad Docker version 17.06.0-ce, build 02c1d87

ronycohen commented 7 years ago

I confirm it's working with the tag v0.6.4 but not from the 0.7.2..... with the bind 0.0.0.0 it's working as well.

adalga commented 7 years ago

Can u try --net=host

martinkoch-geniebelt commented 7 years ago

The following works (sets up a three-node cluster, allowing connection to the html-interface on local ports 8500, 8501, 8502)

docker run -d -p 8500:8500 consul consul agent -data-dir=/consul/data -config-dir=/consul/config -dev -client=0.0.0.0 -bind=0.0.0.0
docker run -d -p 8501:8500 consul consul agent -data-dir=/consul/data -config-dir=/consul/config -dev -client=0.0.0.0 -bind=0.0.0.0 -join 172.17.0.2
docker run -d -p 8502:8500 consul consul agent -data-dir=/consul/data -config-dir=/consul/config -dev -client=0.0.0.0 -bind=0.0.0.0 -join 172.17.0.2
jwermuth commented 7 years ago

I can make it work based on @martinkoch-geniebelt suggestion above. Thx. I removed some of the parameters, to have a smaller (minimal ?) setup that can actually start and connect. I have fixed the version to 0.9.2 so its easier to reproduce, and added a test matrix below.

Run this in 3 terminals and you should see nice connects

docker run --name --rm dev-consul --rm consul:0.9.2 consul agent -dev -bind=0.0.0.0
docker run --rm -P consul:0.9.2 agent -dev -join=172.17.0.2 -bind=0.0.0.0
docker run --rm -P consul:0.9.2 agent -dev -join=172.17.0.2 -bind=0.0.0.0

and be able to do something like this afterwards

$ docker exec dev-consul consul members
Node          Address          Status  Type    Build  Protocol  DC
06a4d5df14f0  172.17.0.3:8301  alive   server  0.9.2  2         dc1
8e43668e2c18  172.17.0.4:8301  alive   server  0.9.2  2         dc1
b15f30cda3d7  172.17.0.2:8301  alive   server  0.9.2  2         dc1

I tried it with a number of versions.

VERSION Note
0.7.0 Works
0.7.5 Works
0.8.0 Works, but you have to provide a unique id yourself (see *A)
0.8.3 Works, but you have to provide a unique id yourself (see *A)
0.8.1 Works, but you have to provide a unique id yourself (see *A)
0.8.4 Works, but you have to provide a unique id yourself (see *A)
0.9.2 Works

*A if you want, you can provide a unique id on the commandline with -node-id=$(uuidgen | awk '{print tolower($0)}')

You nice consul developers. Thanks for a great product. (@slackpad ?) - would it be an idea to update the "Running consul for Development" part of the documentation to use this approach instead so newcommers have a working "Hello Docker-Consul World" example to play with ? (I can do it if you think its a good idea, just let me know).

NB:I tried with multiple docker versions. The error does not seem to be related to docker itself. I run this on an ubuntu 17.04 with a Docker version 17.06.0-ce, build 02c1d87 if that is of interest to anyone.

xiaods commented 6 years ago

docker run -d --rm --name dev-consul consul:latest agent -dev -client=0.0.0.0 -bind=0.0.0.0 docker run -d --rm -P consul:latest agent -dev -join=172.17.0.2 -client=0.0.0.0 -bind=0.0.0.0 docker run -d --rm -P consul:latest agent -dev -join=172.17.0.2 -client=0.0.0.0 -bind=0.0.0.0

it work on consul:latest docker images.