通过Dockerfile安装包时出错

我是Docker的新手。 我正在尝试在Ubuntu映像上安装捆绑软件包作为父映像。

这是我的Dockerfile的外观 –

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" 

在运行这个Dockerfile时,我在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. 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命令,但是我也遇到了类似的错误。 请帮我解决这个问题,现在我已经堵了一段时间了。

另外,当我在做一些改变之后构build图像时,ssh-key在docker镜像上不再存在。 当我注销交互模式并再次login时,同样的情况也会发生,当我再次login时,我新添加的软件包不会显示出来。 我尝试了改变,但问题仍然存在。 我无法弄清楚为什么会发生这种情况。

bundle install需要访问专用仓库时,这种错误很常见。
例如,请参阅docker-library / golang第33期。

另一种方法是复制一个私人和公共密钥,可以访问有问题的存储库。 这是不太安全的,因为密钥将永远embedded在该映像中(即使在稍后的RUN中被删除),它们不会被删除,只是在该文件系统层中“隐藏”,但是如果从下层运行容器图像层。

所以,为了testing,取消注释你的线路,并添加一个

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

另请参见“ 如何使用Dockercaching软件包安装 ”

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