Hi,
I'm working on a small spring boot web service which has to register against an eureka server (also written as Spring Boot application). This is my configuration:
spring:
application.name: awesomeservice
eureka:
client:
serviceUrl:
defaultZone: http://10.0.0.3:8761/eureka/
---
spring:
profiles: docker
eureka.instance.preferIpAddress: true
When running as docker container my service should prefer to register with its IP address instead of the hostname ... but it will always use the docker container id (which is the hostname i guess) when I start it using docker-compose.
Neither setting the euereka.instance.hostname nor ipAddress attribute helps. The docker profile is loaded correctly ... looking forward for tips, hints and answers here.
Kind regards,
codecitizen
How are you determining that it is using the hostname rather than the IP address?
Hi @ryanjbaxter

In the Web Interface of my Eureka Server it links the hostname
Those are just instance ids. If you hover over the links in the browser, or inspect them using the browser developer tools, what do they link to?
The instance with the id 54814d8e4a23 links to http://54814d8e4a23:8080/info
Ah I think you have the wrong property, I think it should be 'eureka.client.instance.preferIpAddress'
The documentation says eureka.instance.preferIpAddress
You are right, it is hard to read YAML on your phone sometimes :)
It is not obvious to me why it is not working, can you provide a sample that reproduces the problem?
What does /eureka/apps say?
Also, what does /env say? To make sure your property was applied.
Works now. This morning I rebuilt the the library and docker image and redeployed it to a newly initialized dev system. It registered against the eureka server with the IP Address, everything is fine. I did some testing, pulled up more services, each registered correctly. So there was probably some issue in my build pipeline. Sorry for bothering.
@spencergibb sorry I can't check the old service for /eureka/apps or /env ... but yesterday I was debugging through EurekaInstanceConfigBean#getHostname(boolean) and it was showing the right values for preferIpAddress and ipAddress.
@codecitizen Hi, could you please pin your application.yml here (only the essential part) of your eureka server and client? I am facing exactly same problem, and I've tried many times not succeeded yet.
I think you should use eureka.instance.instance-id
I also have this problem. Tried a lot of things, but everything failed.
@codecitizen Hi, Please share your application.yml file
IF anybody is interested I found the solution. Client services need to have this in their application.properties (or similiar .yml structure):
eureka.instance.prefer-ip-address=true
eureka.instance.ip-address=IP_OF_MACHINE_ON_WHICH_RUNNING
eureka.instance.instance-eureka.instance.instance-id=eureka.instance.instance-id=${spring.cloud.client.hostname}:${spring.application.name}:${spring.application.instance_id:${random.value}}
@makdeniss ..can you please share your facebook id
i want to communicate with you ....i am facing the same problem ..but everything failed
my nick is my skypeid.
@makdeniss i am unable to understand your last line
eureka.instance.instance-id=eureka.instance.instance-id=${spring.cloud.client.hostname}:${spring.application.name}:${spring.application.instance_id:${random.value}}
sent skype request ..please accept
Hi, it seems network inside docker is rather complex, I can't explain why by this perfectly fixes my problem.
spring:
application:
name: stock-service
cloud:
inetutils:
ignored-interfaces:
- eth0
- eth1
- eth2
- eth3
- lo
Let me know if this also fixes yours.
Hi. I found the following solution.
First add the following code in configuration or service that will be searched
@Autowired
InetUtils inetUtils;
@Bean
// @Profile("!default")
public EurekaInstanceConfigBean eurekaInstanceConfig() {
log.info("\n\n creating eureka instance \n\n\n");
EurekaInstanceConfigBean b = new EurekaInstanceConfigBean(inetUtils);
AmazonInfo info = AmazonInfo.Builder.newBuilder().autoBuild("eureka");
b.setDataCenterInfo(info);
return b;
}
Then you can access the right ip of your service using
String ip = ((AmazonInfo)discoveryClient.getNextServerFromEureka("ADMIN-APPLICATION",false)
.getDataCenterInfo())
.getMetadata().get("public-ipv4");
What was very useful is the endpoint
<EUREKA_URL>/eureka/apps with listed all information about registered services
Hi,
I'm facing the same issue. My service is getting registered with Eureka with Docker container IP. I want it to get registered with the host machine IP address. I tried ignoring network interfaces too. It is still not working.
Any help would be appreciated.
Thanks.
Most helpful comment
Hi, it seems network inside docker is rather complex, I can't explain why by this perfectly fixes my problem.
Let me know if this also fixes yours.