【问题标题】:Spring Cloud Apps Running in Container - Runs on Local Machine, Fails on Google Cloud在容器中运行的 Spring Cloud 应用程序 - 在本地机器上运行,在 Google Cloud 上失败
【发布时间】: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/.sshknown_hosts 文件包含在此目录中。
  • 以上(使用volumes 作为我的 SSH 密钥)在我的开发机器上运行良好。

任何帮助将不胜感激。

【问题讨论】:

    标签: docker spring-boot google-cloud-platform spring-cloud


    【解决方案1】:

    最终,我能够解决这个问题。虽然这实际上是在几天前解决的,但我发布了通用解决方案,希望它在未来可能有用。

    首先,我能够确认(通过使用curl 调用我的服务器的一个端点)根本问题是配置服务器无法提取 git 存储库。

    最初,我有点困惑 - 我的 SSH 密钥已设置好,我能够从 VM 中 git clone 回购。但是,在查看Spring Cloud documention 时,我发现known_hosts 文件必须是ssh-rsa 格式。但是,VM 的 ssh 实用程序以不同的格式保存它们(即使我的开发机器和 VM 都运行 Debian 9)。要解决此问题,请以 ssh-rsa 格式添加相应的 GitLab(或其他主机)条目。检查一个人的/etc/ssh/sshd_config 也可能很有价值。

    【讨论】:

      猜你喜欢
      • 2022-01-04
      • 1970-01-01
      • 1970-01-01
      • 2011-06-17
      • 2022-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多