I used docker to start a micro service, and started the docker-consul container, can not modify the registered address of consul.
FROM ubuntu:latest
RUN mkdir /sms
WORKDIR /sms
ADD . /sms
CMD ["./sms"]
sms:
build: .
environment:
- MICRO_REGISTRY_ADDRESS=http://consul:8501
volumes:
- ./logs/:/sms/logs/
- ./etc/env_strings.conf:/etc/env_strings.conf
links:
- consul
consul:
image: progrium/consul
Attaching to sms_consul_1, sms_sms_1
consul_1 | ==> WARNING: It is highly recommended to set GOMAXPROCS higher than 1
consul_1 | ==> Starting Consul agent...
consul_1 | ==> Starting Consul agent RPC...
consul_1 | ==> Consul agent running!
consul_1 | Node name: '70f340bc6eec'
consul_1 | Datacenter: 'dc1'
consul_1 | Server: false (bootstrap: false)
consul_1 | Client Addr: 0.0.0.0 (HTTP: 8500, HTTPS: -1, DNS: 53, RPC: 8400)
consul_1 | Cluster Addr: 192.168.42.2 (LAN: 8301, WAN: 8302)
consul_1 | Gossip encrypt: false, RPC-TLS: false, TLS-Incoming: false
consul_1 | Atlas: <disabled>
consul_1 |
consul_1 | ==> Log data will now stream in as it occurs:
consul_1 |
consul_1 | 2016/06/23 12:50:45 [INFO] serf: EventMemberJoin: 70f340bc6eec 192.168.42.2
consul_1 | 2016/06/23 12:50:45 [WARN] serf: Failed to re-join any previously known node
consul_1 | 2016/06/23 12:50:45 [ERR] agent: failed to sync remote state: No known Consul servers
sms_1 | 2016/06/23 12:50:45 Listening on [::]:50573
sms_1 | 2016/06/23 12:50:45 Broker Listening on [::]:34602
sms_1 | 2016/06/23 12:50:45 Registering node: service.sms-F05AE48C
sms_1 | 2016/06/23 12:50:45 consul.watch: Watch (type: services) errored: Get http://127.0.0.1:8500/v1/catalog/services: dial tcp 127.0.0.1:8500: getsockopt: connection refused, retry in 5s
sms_1 | time="2016-06-23T12:50:45Z" level=error msg="Put http://127.0.0.1:8500/v1/agent/service/register: dial tcp 127.0.0.1:8500: getsockopt: connection refused"
sms_sms_1 exited with code 0
How should I solve this problem? thx :)
Have you tried not specifying http:// in the registry address?
Error messages that do not specify http:// are the same.
sms_1 | time="2016-06-23T13:44:18Z" level=error msg="Put http://127.0.0.1:8500/v1/agent/service/register: dial tcp 127.0.0.1:8500: getsockopt: connection refused"
Where you have this - MICRO_REGISTRY_ADDRESS=http://consul:8501 change it to - MICRO_REGISTRY_ADDRESS=consul:8501
Wait. Your consul address is not different. How would this even work? It's still set to 8500.
Client Addr: 0.0.0.0 (HTTP: 8500, HTTPS: -1, DNS: 53, RPC: 8400)
okay. I try:)
There is still a problem.
sms_1 | 2016/06/23 14:00:22 consul.watch: Watch (type: services) errored: Get http://127.0.0.1:8500/v1/catalog/services: dial tcp 127.0.0.1:8500: getsockopt: connection refused, retry in 5s
consul_1 | 2016/06/23 14:00:22 [WARN] Service name "service.sms" will not be discoverable via DNS due to invalid characters. Valid characters include all alpha-numerics and dashes.
Please specify your entire config. It's difficult to debug without having full context.
Here's a simple configuration that does work.
consul:
command: -server -bootstrap -rejoin
image: progrium/consul:latest
api:
command: api
build: .
environment:
- MICRO_REGISTRY_ADDRESS=consul:8500
links:
- consul
Hi @asim
After the start of the service, the consul.wath connection service is rejected.I don't know how to solve it:(
docker-compose.yml
sms:
build: .
environment:
- MICRO_REGISTRY_ADDRESS=consul:8500
volumes:
- ./logs/:/sms/logs/
- ./etc/env_strings.conf:/etc/env_strings.conf
links:
- consul
consul:
command: -server -bootstrap -rejoin
image: progrium/consul:latest
server log:
Creating sms_consul_1
Creating sms_sms_1
Attaching to sms_consul_1, sms_sms_1
consul_1 | ==> WARNING: Bootstrap mode enabled! Do not enable unless necessary
consul_1 | ==> WARNING: It is highly recommended to set GOMAXPROCS higher than 1
sms_1 | 2016/06/24 02:15:20 Listening on [::]:34066
consul_1 | ==> Starting raft data migration...
sms_1 | 2016/06/24 02:15:20 Broker Listening on [::]:46361
consul_1 | ==> Starting Consul agent...
sms_1 | 2016/06/24 02:15:20 Registering node: sms-7E67AC78
consul_1 | ==> Starting Consul agent RPC...
consul_1 | ==> Consul agent running!
consul_1 | Node name: '6dd7183da9a7'
consul_1 | Datacenter: 'dc1'
consul_1 | Server: true (bootstrap: true)
consul_1 | Client Addr: 0.0.0.0 (HTTP: 8500, HTTPS: -1, DNS: 53, RPC: 8400)
consul_1 | Cluster Addr: 192.168.42.2 (LAN: 8301, WAN: 8302)
consul_1 | Gossip encrypt: false, RPC-TLS: false, TLS-Incoming: false
consul_1 | Atlas: <disabled>
consul_1 |
consul_1 | ==> Log data will now stream in as it occurs:
consul_1 |
consul_1 | 2016/06/24 02:15:20 [INFO] serf: EventMemberJoin: 6dd7183da9a7 192.168.42.2
consul_1 | 2016/06/24 02:15:20 [INFO] serf: EventMemberJoin: 6dd7183da9a7.dc1 192.168.42.2
consul_1 | 2016/06/24 02:15:20 [INFO] raft: Node at 192.168.42.2:8300 [Follower] entering Follower state
consul_1 | 2016/06/24 02:15:20 [INFO] consul: adding server 6dd7183da9a7 (Addr: 192.168.42.2:8300) (DC: dc1)
consul_1 | 2016/06/24 02:15:20 [INFO] consul: adding server 6dd7183da9a7.dc1 (Addr: 192.168.42.2:8300) (DC: dc1)
consul_1 | 2016/06/24 02:15:20 [ERR] agent: failed to sync remote state: No cluster leader
sms_1 | 2016/06/24 02:15:20 consul.watch: Watch (type: services) errored: Get http://127.0.0.1:8500/v1/catalog/services: dial tcp 127.0.0.1:8500: getsockopt: connection refused, retry in 5s
Most helpful comment
Here's a simple configuration that does work.