通过 Dockerfile 安装包时出错

Error while installing bundle via Dockerfile

我是 Docker 的新手。我正在尝试在 ubuntu 图像上安装 bundle 作为父图像。

这是我的 Docker 文件的样子 -

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"

在 运行 这个 Docker 文件上,我在 bundle install 命令中得到一个错误,我得到错误 Host key verification failed. fatal: Could not read from remote repository.Please make sure you have the correct access rights and the repository exists. 我尝试使用交互模式 运行 bundle install 命令,但我也遇到了类似的错误。请帮我解决这个问题,我已经被封锁了一段时间了。

此外,当我在进行一些更改后构建映像时,docker 映像中不再存在 ssh 密钥。当我注销交互模式并再次登录时,有时会发生同样的情况,当我再次登录时,我新添加的包不会出现。我尝试提交更改,但问题仍然存在。我不明白为什么会这样。

bundle install 需要访问私有存储库时,这种错误很常见。
例如,参见 docker-library/golang issue 33

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.

所以,为了测试,取消注释你的行并添加

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

另请参阅“How to cache bundle install with Docker

你应该先RUN bundle install,然后ADD . $app