3
votes

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.

2

2 Answers

8
votes

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
0
votes

Run the container with -p 12345:12345 to publish the port so that you can access the container from your host machine through the specified port