1

I have a spring boot config server which is fetching config files from a remote private GitHub repository using ssh. The service works perfectly when running in local but when I run the service through docker, it runs but unfortunately couldn't fetch the config repo and the reason is I am not able to correctly set up ssh in the docker container.

Here's my application property files -

server:
  port: 8888
spring:
  application:
    name: configserver
  cloud:
    config:
      server:
        git:
          uri: something_url
          ignoreLocalSshSettings: false
          passphrase: phassphrase
          defaultLabel: master

Here's so far what I have tried with my docker file -

FROM openjdk:11
ARG SSH_PRIVATE_KEY
RUN mkdir ~/.ssh/
RUN echo "${SSH_PRIVATE_KEY}" > ~/.ssh/id_ecdsa
RUN chmod 600 ~/.ssh/id_ecdsa
RUN ssh-keyscan github.com >> ~/.ssh/known_hosts
RUN bash -c 'echo -e "Host *\n\tIdentifyFile ~/.ssh/id_ecdsa" >> ~/.ssh/config >> ~/.ssh/config'
ARG JAR_FILE=build/libs/*.jar
COPY ${JAR_FILE} config-server.jar
ENTRYPOINT ["java", "-jar", "/config-server.jar"]

I am using the following command to create the image -

docker build --build-arg SSH_PRIVATE_KEY="$(cat ~/.ssh/id_ecdsa)" -t config-server .

The container starts perfectly but as soon as I run the eureka server container it throws the error saying AUTH FAILS

  • [Please do not upload images of code/data/errors.](//meta.stackoverflow.com/q/285551) Can you [edit] the question to include a [mcve], including the text of your Dockerfile and any output directly in the question? Passing an ssh private key as a Docker build argument is usually inadvisable since it can often easily be extracted by anyone with a copy of the built image; I'd usually recommend running any `git` commands on the host before you build your image. – David Maze Jan 03 '23 at 01:22
  • It actually worked after making a few changes to the docker file. I cannot git on the host as the git pull is done by the spring boot config server inside the container after so other service connects to config server. Do you have any other suggestion so that I won't have to use it as a arg in docker build? – Yash Udhlani Jan 03 '23 at 19:33

0 Answers0