【发布时间】:2018-07-20 19:51:49
【问题描述】:
这是我之前在 Stack Overflow 上提出的问题的后续。我正在构建一个基于 Spring Boot Cloud 的服务。我正在使用 Docker 在容器中运行它。我终于让它在我的本地机器上运行了。
# Use postgres/example user/password credentials
version: '3.2'
services:
db:
image: postgres
ports:
- 5000:5432
environment:
POSTGRES_PASSWORD: example
volumes:
- type: volume
source: psql_data
target: /var/lib/postgresql/data
networks:
- app
restart: always
config:
image: kellymarchewa/config_server
ports:
- 8888:8888
networks:
- app
volumes:
- /home/kelly/.ssh:/root/.ssh
restart: always
search:
image: kellymarchewa/search_api
networks:
- app
restart: always
ports:
- 8081:8081
depends_on:
- db
- config
- inventory
inventory:
image: kellymarchewa/inventory_api
depends_on:
- db
- config
# command: ["/home/kelly/workspace/git/wait-for-it/wait-for-it.sh", "config:8888"]
ports:
- 8082:8082
networks:
- app
restart: always
volumes:
psql_data:
networks:
app:
之前,我在处理客户端对配置服务器的依赖时遇到了困难(在客户端尝试访问配置服务器时,配置服务器还没有完全启动)。但是,我使用spring-retry 解决了这个问题。现在,虽然我可以在本地机器上使用 docker-compose up 运行它,但在 Google Cloud 服务托管的虚拟机上运行相同的命令(使用相同的 Docker 文件)会失败。
inventory_1 | java.lang.IllegalStateException: Could not locate PropertySource and the fail fast property is set, failing
但是,它似乎正在查询适当的位置:
inventory_1 | 2018-02-10 00:23:00.945 INFO 1 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at: http://config:8888
我不确定是什么问题,因为两者都使用相同的 docker-compose 文件运行,并且配置服务器本身正在启动。
配置服务器的 application.properties:
server.port=8888
management.security.enabled=false
spring.cloud.config.server.git.uri=git@gitlab.com:leisurely-diversion/configuration.git
# spring.cloud.config.server.git.uri=${HOME}/workspace/eclipse/leisurely_diversion_config
客户端 bootstrap.properties:
spring.application.name=inventory-client
#spring.cloud.config.uri=http://localhost:8888
spring.cloud.config.uri=http://config:8888
management.security.enabled=false
spring.cloud.config.fail-fast=true
spring.cloud.config.retry.max-attempts=10
spring.cloud.config.retry.initial-interval=2000
编辑:
经过进一步检查,配置服务器似乎无法提取存储应用程序属性的 git 存储库。但是,我不确定为什么会出现这种行为,原因如下:
- 我已将 GitLab 的 SSH 密钥添加到我的 VM。
- 我可以从我的 VM 中提取存储库。
- 我在我的 docker-compose 文件中使用
volumes来引用/home/kelly/.ssh。known_hosts文件包含在此目录中。 - 以上(使用
volumes作为我的 SSH 密钥)在我的开发机器上运行良好。
任何帮助将不胜感激。
【问题讨论】:
标签: docker spring-boot google-cloud-platform spring-cloud