Nicolas Mongrain-Lacombe Nicolas Mongrain-Lacombe - 2 months ago 37
Java Question

How to make Spring Cloud Consul register with external IP?

How to make Spring Cloud Consul register with external IP?

I run spring boot applications with spring cloud consul in docker.
The application is running inside a docker network on a docker swarm.

This means that if spring consul registers with the hostname or the IP address it will get an hostname or ip address that is internal to the docker swarm. My consul server is outside the docker swarm.

Answer

You can set spring.cloud.consul.discovery.ipAddress externally and set the property spring.cloud.consul.discovery.preferIpAddress=true.

Alternatively, you can control which network interfaces to derive an ip address from.

In Brixton you can ignore interfaces:

spring:
  cloud:
    inetutils:
      ignoredInterfaces:
        - docker0
        - veth.*

In Camden (currently RC1) you can also whitelist networks:

spring:
  cloud:
    inetutils:
      preferredNetworks:
        - 192.168
        - 10.0
Comments