I'm running Spring Cloud Eureka inside my Docker VM. I have services registering to it, but they use their IP adress from inside the Docker VM, but to be able to use them properly i need them to use the IP adress i can access from outside the VM.
For example inside my VM the register using 172.x.x.x and i can access the REST interface from my browser using 192.168.x.x.x. I need them to register as 192.168.x.x.x.
How can i tell my service to register with a specific IP adress?
When you connect an existing container to a different network using docker network connect , you can use the --ip or --ip6 flags on that command to specify the container's IP address on the additional network. In the same way, a container's hostname defaults to be the container's ID in Docker.
By default, the container is assigned an IP address for every Docker network it connects to. And each network is created with a default subnet mask, using it as a pool later on to give away the IP addresses. Usually Docker uses the default 172.17.
AFAIK, in the case of Docker for Linux (standard distribution), the IP address of the host will always be 172.17. 0.1 (on the main network of docker, see comments to learn more). This is true of containers attached to the docker0 default bridge interface.
Both previous answers are correct, but I'll make copy-pasting easier.
What you should do is add an environment variable with the host IP when starting your container and in your Spring Boot application.yml
file includes it.
application.yml
eureka:
instance:
# Necessary for Docker as it doesn't 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
You can configure it in your application.yml
:
eureka:
instance:
ipAddress: 192.168.x.x
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With