I took this example https://github.com/paulc4/microservices-demo and I created 3 docker images from it, with the following Dockerfiles:
springdocker-registration:
<For those who are working with docker-compose and if in your services yml file you have the following:
eureka:
client:
serviceUrl:
# Will get overridden in docker-compose
defaultZone: http://localhost:1111/eureka
You can override this in your docker-compose file like below while running docker-compose up
version: "3.3"
services:
# Other services registered above
web:
image: springdocker-web
environment:
# Important for clients to register with eureka
- eureka.client.serviceUrl.defaultZone=http://registration:8761/eureka/
ports:
- "3333:3333"
depends_on:
- registration
- accounts
links:
- registration
Tested on Docker version 19.03.8
Since its running in docker, don't use localhost. Docker compose lets you refer to container names.
eureka:
client:
serviceUrl:
defaultZone: http://registration:1111/eureka
Side note: defaultZone must be exact, I spent 2 days wondering why it wouldn't work since intellij auto completes to do default-zone which wont work.