【发布时间】:2017-11-28 00:56:40
【问题描述】:
我有一个 Spring Cloud 配置服务器并将其打包为 Docker 映像,然后我有 Spring Cloud Eureka 服务器,它也打包为 Docker 映像。
当我使用 docker compose 运行这两个时,出现以下错误。
discovery-service_1 | 2017-06-24 15:36:12.059 INFO 5 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at: http://config-service:9001
discovery-service_1 | 2017-06-24 15:36:12.997 WARN 5 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Could not locate PropertySource: I/O error on GET request for "http://config-service:9001/cls-discovery-service/default": Connection refused (Connection refused); nested exception is java.net.ConnectException: Connection refused (Connection refused)
虽然配置服务已经启动并成功运行,但是发现服务由于某种原因仍然没有找到它。
这里使用的 Docker compose 文件是这个
version: '2'
services:
config-service:
image: cloudsea/cls-config-service
ports:
- 9001:9001
expose:
- "9001"
discovery-service:
image: cloudsea/cls-discovery-service
depends_on:
- config-service
environment:
CLOUD_SEA_CONFIG_SERVER_URI: http://config-service:9001
EUREKA_DEFAULT_ZONE_URL: http://discovery-service:8761/eureka/
ports:
- 8761:8761
links:
- config-service:config-service
下面是 DISCOVERY SERVICE 的 bootstrap.properties
spring.cloud.config.uri = ${CLOUD_SEA_CONFIG_SERVER_URI:http://localhost:9001}
spring.application.name = ${SPRING_APPLICATION_NAME:cls-discovery-service}
下面是位于 github 中的 DISCOVERY SERVICE 的 cls-discovery-service.properties。
server.port=${SERVER_PORT:8761}
eureka.client.registerWithEureka: false
eureka.client.fetchRegistry: false
eureka.client.serviceUrl.defaultZone: ${EUREKA_DEFAULT_ZONE_URL:http://localhost:8761/eureka/}
eureka.server.eviction-interval-timer-in-ms: 1000
我假设我的 docker-compose.yml 有问题,但我不确定。
任何帮助我都会坚持几个小时...接近几天:(
【问题讨论】:
-
单独运行docker镜像怎么样?先运行“config-service”,再运行“discovery-service”?
-
如果我这样做,它可以完美运行,但问题是我必须将配置 uri 指定为
http://DOCKER_HOST:9001。我假设问题出在 docker compose 但不知道它是什么???
标签: spring-boot docker-compose spring-cloud spring-cloud-netflix spring-cloud-config