jordiPons
jordiPons

Reputation: 174

Host key verification failed fetching git in a docker container

I have a private ruby gem in github that I'm using in another repository so when I build the docker container and it tries to perform the bundle install I get the following error:

Host key verification failed. fatal: Could not read from remote repository.

I've checked that my user has the rights to read this gem. The command that I'm using is this:

docker build \
-t quay.io/org/${APP}:${VERSION} \
.

And my Dockerfile is this simple file:

FROM ruby:2.4.2-onbuild
ENTRYPOINT ["./entrypoint.sh"]

Where the entrypoint.sh file it just perform this:

bundle exec ruby runner.rb

I guess that somehow I need to pass the user and the ssh-key into the container but I was not able to figure out how.

Upvotes: 0

Views: 1754

Answers (2)

Since no one seems to have answered this question, I'll add mine here-

Add this to the start of your Dockerfile:

FROM ruby:2.5.8

RUN git config --global url."https://github.com/".insteadOf '[email protected]:'

Explanation: Bundle is using git to verify the source for the gems it's installing, and we don't want to use ssh as the means of communication to do this. Otherwise, you need a private key in your docker container to communicate through ssh. You want to avoid copying a private key into the container if you're ever going to share it with anyone. Also, it is simpler to do it this way.

Now you should be able to run bundle install as part of your build steps like so:

FROM ruby:2.5.8

RUN git config --global url."https://github.com/".insteadOf '[email protected]:'

WORKDIR /app

COPY Gemfile Gemfile.lock  /app/

RUN bundle install

Upvotes: 1

edupo
edupo

Reputation: 306

There is no need to share or push keys into a container. Maybe this answer can help you to continue.

Upvotes: 0

Related Questions