Consul share network from docker

Viewed 362

There is consul server in docker.

  vote-consul-server:
    image: consul:1.7.2
    environment:
      CONSUL_BIND_INTERFACE: eth0
    ports:
      - "${CONSUL_PORT}:8500"

It generates hosts for registred applications. The main problem is that anothers applications can't communicate between each other if they are not in docker.

For example: I have config-service (docker with consul), user-service(IDE). When user-service starts, it asks for configurations from config-server, but consul gives not correct link (available only in docker network).

c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://83a6c7ab12d0:8888/

How to publish all links from consul(docker)?

2 Answers

First of all - need to define IP address configuration in bootstrap.yaml

spring:
  ...
  cloud:
    consul:
      host: ${CONSUL_HOST}
      port: ${CONSUL_PORT}
      discovery:
        ip-address: ${CONSUL_HOST}
        prefer-ip-address: true

The main properties are: ip-address and prefer-ip-address.

If all aplications work in one network - problem doesn't exist. For example: all services work in docker.

Related