在使用docker-compose时,应用程序不能注册为eureka

我拿着这个例子https://github.com/paulc4/microservices-demo ,我用它创build了3个docker镜像,用下面的Dockerfiles:

springdocker登记:

FROM openjdk:8-jdk-alpine VOLUME /tmp ADD target/microservice-demo-1.1.0.RELEASE.jar app.jar EXPOSE 1111 ENTRYPOINT exec java -jar /app.jar registration 

springdocker账户:

 FROM openjdk:8-jdk-alpine VOLUME /tmp ADD target/microservice-demo-1.1.0.RELEASE.jar app.jar EXPOSE 2222 ENTRYPOINT exec java -jar /app.jar accounts 

springdocker的web:

 FROM openjdk:8-jdk-alpine VOLUME /tmp ADD target/microservice-demo-1.1.0.RELEASE.jar app.jar EXPOSE 3333 ENTRYPOINT exec java -jar /app.jar web 

如果我单独运行这三个图像一切正常, webaccounts服务注册到registration服务(这是尤里卡registry的实现),我可以使用我的应用程序。 但是,使用docker-compose.yml docker-compose和以下docker-compose.yml文件时

 version: "3.4" services: registration: image: springdocker-registration ports: - "1111:1111" accounts: image: springdocker-accounts ports: - "2222:2222" links: - registration depends_on: - registration web: image: springdocker-web ports: - "3333:3333" depends_on: - registration - accounts links: - registration 

服务webaccounts无法注册到registration服务。 这里是应用程序的configuration文件:

登记-server.yml:

 eureka: instance: hostname: localhost client: registerWithEureka: false fetchRegistry: false serviceUrl: defaultZone: http://localhost:1111/eureka/ server: port: 1111 spring: thymeleaf: enabled: false 

账户-server.yml:

 spring: application: name: accounts-service freemarker: enabled: false thymeleaf: cache: false prefix: classpath:/accounts-server/templates/ error: path: /error server: port: 2222 eureka: client: serviceUrl: defaultZone: http://localhost:1111/eureka instance: leaseRenewalIntervalInSeconds: 5 preferIpAddress: true 

networkingserver.yml

 spring: application: name: web-service freemarker: enabled: false thymeleaf: cache: false prefix: classpath:/web-server/templates/ error: path: /error eureka: client: serviceUrl: defaultZone: http://localhost:1111/eureka instance: leaseRenewalIntervalInSeconds: 5 preferIpAddress: true server: port: 3333 

我可以发布docker-compose up的完整控制台日志,但我认为这是有趣的一点:

 1: ERROR RedirectingEurekaHttpClient - Request execution error com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused (Connection refused) 1: ERROR DiscoveryClient - DiscoveryClient_WEB-SERVICE/e3b5e6b3396c:web-service:3333 - was unable to refresh its cache! status = Cannot execute request on any known server com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server