簡體   English   中英

Spring Boot Cloud 配置、GitLab、Docker 和 SSH 密鑰設置

[英]Spring Boot Cloud Configuration, GitLab, Docker and SSH Key Set Up

我正在嘗試構建一個 Spring Cloud 應用程序,該應用程序利用托管在 GitLab 上的存儲庫來存儲配置詳細信息。 我可以在我的本地機器上運行它。 但是,由於需要 SSH 密鑰,我正在努力將其放入容器中。 例如,我的配置服務器的 application.properties 文件:

server.port=8888
spring.cloud.config.server.git.uri=git@gitlab.com:repo

我已經參考了這個StackOverflow 問題 但是,我使用的是 docker-compose 文件。

   # 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
    networks:
      - app
    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
    ports:
      - 8080:8080
    networks:
      - app
    restart: always
volumes:
  psql_data:
networks: 
  app:

無論如何,當使用撰寫文件時,是否可以從 docker 容器訪問私有 git 存儲庫? 謝謝。

解決這個問題的兩個步驟:

  1. 在本地機器上生成一個 SSH 密鑰文件,docker 容器將在該文件中運行

  2. 修改 docker-composer 文件,添加一個 volume 選項,將 .ssh 文件夾從本地機器映射到 docker 容器。

     config: image: kellymarchewa/config_server volumes: - /root/.ssh:/root/.ssh networks: - app restart: always

跳這可以解決您的問題,如果您有任何問題,可以與我聯系。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM