Springboot client unable register with Eureka using Docker container id
In docker the container-id will be set as the hostname of the container by default. Containers can talk with each other using container-id (or here hostname)
So this issue can be solved by preferring hostname instead of ip.
But only way of making sure that registration happens through hostname is by setting eureka.instance.hostname
reference
In docker you can set the container-id at run-time from the hostname by using the entry point as shell script (for example start.sh) and the script should be something similar to
#!/bin/shexport HOST_NAME=`hostname`java -Djava.security.egd=file:/dev/./urandom -Xmx1024m -jar /app.jar
and make sure you add eureka.instance.hostname=${HOST_NAME}
in your application.yml
or you can reuse the HOSTNAME
variable which is set by default in Docker and configuration becomes eureka.instance.hostname=${HOSTNAME}
I have added the same info in documentation
Update: looks like this can also be fixed by using endpoint_mode: dnsrr
in the compose file (have to confirm). Refer this
Try setting eureka.instance.hostname
in your client config.
I know this is an old question but this answer might be helpful to someone. After trying out a number of solutions, I noticed that a hostname environment variable(HOSTNAME) already exists in Ubuntu. My docker containers use the openjdk:8-jdk-alpine
base. If you're using an Ubuntu base you can simply solve this issue by adding the following parameters to the properties files of all your eureka clients:
eureka.instance.hostname=${HOSTNAME}spring.cloud.client.hostname=${HOSTNAME}
The app will pick up the container's hostname which is the container id and pass that to the eureka server.