Sign up for Docker Eureka with a dedicated IP address

I am running Spring Cloud Eureka inside my Docker VM. I have registration services, but they use their IP address from inside the Docker VM, but in order to be able to use them properly, I need them to use an IP address that I can access from outside the virtual machine.

For example, inside my virtual machine, a register using 172.xxx and i can access the REST interface from my browser using 192.168.xxx. I need them to register as 192.168.xxx

How can I inform my service about registration with a specific IP address?

+6
source share
4 answers

You can configure it in application.yml :

 eureka: instance: ipAddress: 192.168.xx 
0
source

Both of the previous answers are correct, but I will make copying easier.

What you have to do is add an environment variable with the host IP address when starting your container, and include it in your Spring Boot application.yml file.

application.yml

 eureka: instance: # Necessary for Docker as it does not have DNS entries prefer-ip-address: true # Necessary for Docker otherwise you will get 172.0.0.x IP ip-address: "${HOST}" client: serviceUrl: # Location of your eureka server defaultZone: http://192.168.0.107:8761/eureka/ 

Running with Docker

 docker run -p <port>:<port> -e HOST='192.168.0.106' <image name> 

Running with docker-compose

 my_service: image: image_name environment: - HOST=192.168.0.106 ports: - your_port:container_port 
+3
source

Register with Eureka with an individual IP address and your own PORT:

 server: port: 18090 eureka: instance: prefer-ip-address: true ip-address: 10.150.160.21 non-secure-port: 8080 

I am facing a situation where 10.150.160.21:8080 maps to 192.168.1.124:18090 through a firewall. The application runs on 192.168.1.124:18090, but must register on Eureka from 10.150.160.21:8080.

It works for me.

+1
source

You can use environment variables in eureka configuration in application.yml

In the following example, I use the $HOST and $PORT environment variables to tell the eureka client which values ​​to use. In my case, these variables are set by Mesos / Marathon. You can find other useful variables set by Docker.

The following works for me:

 eureka: client: serviceUrl: defaultZone: http://discovery.marathon.mesos:31444/eureka/ registerWithEureka: true fetchRegistry: true instance: appname: configserver health-check-url: /health prefer-ip-address: true ip-address: "${HOST}" # mesos/marathon populates this in the environment non-secure-port: "${PORT}" # mesos/marathon populates this in the environment 
0
source

Source: https://habr.com/ru/post/987573/


All Articles