0

I'm using spring cloud eureka for microservice registration in a dockerised environment on aws.

As i'm using dockers ephemeral port mapping the port exposed on the container host is unknown. To overcome that i've a custom EurekaInstanceConfigBean that asks the docker daemon on the host for the assigned port so i can use that to register with eureka.

That all works fine until registration starts. The EurekaDiscoveryClientConfiguration contains a @EventListener(EmbeddedServletContainerInitializedEvent.class) that overrides the external port i've assigned in my custom EurekaInstanceConfigBean and sets it back to the local port inside the container.

I think the listeners purpose is to support auto port assignment in case of server.port=0 but in my setup it's breaking things.

The question is: Can i somehow stop the EurekaDiscoveryClientConfiguration to override my manually set port? Can i somehow use my own EurekaDiscoveryClientConfiguration?

Dirk Lachowski
  • 3,121
  • 4
  • 40
  • 66

1 Answers1

0

You could use host networking and thus the docker container uses the network stack of the host which makes the service accessible on it's IP addresses.

I used this by utilizing docker-compose. The services all have random ports despite the edge services which are working as reverse proxy (in my case zuul based). these edge services have stable ports.

Patrick Cornelissen
  • 7,968
  • 6
  • 48
  • 70
  • Hi Patrick, my problem is setting the port in the config bean so i can register with eureka. Either way, i've now overwritten the `EurekaInstanceConfigBean` with a version that ignores `setNonSecurePort` and exposes an alternative setter - that works but feels way to hackish... – Dirk Lachowski Jul 31 '16 at 13:33