3

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)?

yazabara
  • 1,253
  • 4
  • 21
  • 39

2 Answers2

1

Since every container has own IP and may have own network, you can try to use host networking:

docker run --rm -d --network host --name vote-consul-server

For more details, see host networking tutorial.

Also, you can learn about networking from the container’s point of view

Yasen
  • 4,241
  • 1
  • 16
  • 25
0

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.

yazabara
  • 1,253
  • 4
  • 21
  • 39