Search code examples
gitdockersshbundlergit-clone

Error while installing bundle via Dockerfile


I am new to Docker. I am trying to install bundle on an ubuntu image as the parent image.

Here is what my Dockerfile looks like -

FROM ubuntu
RUN apt-get update 
RUN apt-get update && apt-get install -y curl
RUN apt-get remove -y openssh-client
RUN apt-get autoclean && apt-get update && apt-get install -y openssh-
server 
#INSTALL ESSESNTIAL PACKAGES 
#RUN apt-get -y install zsh htop
RUN DEBIAN_FRONTEND="noninteractive" apt-get install -y mysql-server
#RUN curl -sSL https://rvm.io/mpapis.asc | gpg --import -
RUN apt-get install -y software-properties-common
RUN apt-add-repository -y ppa:rael-gc/rvm
RUN apt-get update && apt-get install -y rvm 
RUN /bin/bash -l -c "rvm install ruby-2.2.3" 
ENV app /app
RUN mkdir $app
WORKDIR $app
ADD . $app

#RUN ssh-keygen -f id_rsa -t rsa -N ''
#RUN mkdir /root/.ssh
#RUN ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
RUN /bin/bash -l -c "gem install bundler"
RUN /bin/bash -l -c "bundle -v"
RUN apt-get update && apt-get install -y git
RUN /bin/bash -l -c "bundle install"

On running this Dockerfile, I get an error at the bundle install command, I get the error Host key verification failed. fatal: Could not read from remote repository.Please make sure you have the correct access rights and the repository exists. I tried running the bundle install command using the interactive mode, but I got a similar error there as well. Please help me in resolving this issue, I have been blocked on this for sometime now.

Also, the ssh-keys weren't present anymore on the docker image when I build the image after making some changes. Same happens at times when I logout of the interactive mode and login again, my newly added packages don't show up when I login again. I tried committing the changes, but still the issue persisted. I cannot figure out why this is happening.


Solution

  • That kind of error is common when bundle install needs to access private repos.
    See docker-library/golang issue 33 for instance.

    The other way is to COPY in a private and public key that has access to pull the repositories in question. This is less secure because the keys will be forever embedded in that image (even if removed at a later RUN), they are not deleted, just "hidden" in that file system layer, but still accessible if you run a container from that lower image layer.

    SO, for testing, uncomment your lines and add a

    COPY yourPrivateKey /root/.ssh/id-rsa
    COPY yourPublicKey /root/.ssh/id-rsa
    

    See also "How to cache bundle install with Docker"

    You should RUN bundle install first, then ADD . $app