I'm developing a project using Spring Boot Cloud with Eureka. When i run everything on my machine everything works fine. But when I start using Docker:
- if I put EurekaServer in Docker container and run it, all services on localhost can register to it
- if I put a service in Docker container and run it, it cant't register to neither EurekaServer running on localhost nor EurekaServer running in Docker container
I also have Cloud Config Server running on localhost:8888 and services in Docker container cant access it. Tried running it all in docker-compose, docker stack, none of it works.
bootstrap.yml for Eureka Server:
spring:
application:
name: conhub-eureka-server
cloud:
config:
uri:
- http://localhost:8888
server:
port: 8761
eureka:
client:
register-with-eureka: false
fetch-registry: false
Dockerfile for Eureka server (I use fabric8 docker maven plugin):
FROM openjdk
VOLUME /tmp
ADD maven/conhub-eureka-server-0.0.1-SNAPSHOT.jar myapp.jar
RUN sh -c 'touch /myapp.jar'
EXPOSE 8761
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-
jar","/myapp.jar"]
bootstrap.yml for example service (it's a zuul gateway):
server:
port: 8765
spring:
cloud:
config:
enabled: true
uri: http://localhost:8888
application:
name: conhub-gateway
eureka:
client:
service-url:
default-zone: http://${EUREKA_SERVER_HOST:localhost}:8761/eureka
Dockerfile for example service:
FROM openjdk
VOLUME /tmp
ADD maven/conhub-gateway-0.0.1-SNAPSHOT.jar myapp.jar
RUN sh -c 'touch /myapp.jar'
EXPOSE 8765
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-
jar","/myapp.jar"]
I've read many posts here and tried everything but with no success. I guess my biggest surprise is why a service in a container can't access in my case http://localhost:8888 for configs? I can easily access it manually.
EDIT 2 Well I finally found the mistake. In a EurekaClient the proper way of writing delault zone for EurekaServer is: defaultZone not default-zone. Thanks to this post