简体   繁体   中英

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

I am attempting to use to build a Spring Cloud application that utilizes a repository hosted on GitLab to store configuration details. I can run it on my local machine. However, I am struggling to place it in a container due to the need for SSH keys. For example, my application.properties files for the configuration server:

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

I have referenced this StackOverflow question ; however, I am using a docker-compose file.

   # 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:

Is there anyway to access a private git repo from docker containers when a compose file is used? Thanks.

Two steps to resolve this problem:

  1. Generate a SSH key file in the local machine which the docker container will run at

  2. Modify the docker-composer file to add a volume option to mapping the .ssh folder from the local machine to docker container.

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

Hop this can resolve your problem, if you have any issue, you can contract me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM