【问题标题】:Error while installing bundle via Dockerfile通过 Dockerfile 安装包时出错
【发布时间】:2017-10-12 13:15:47
【问题描述】:

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

这是我的 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. 我尝试使用交互模式运行bundle install 命令,但在那里我也遇到了类似的错误。请帮我解决这个问题,我已经被阻止了一段时间了。

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

【问题讨论】:

  • 我假设您在 github 访问中使用 ssh-keys。但是我没有看到您将 SSH 密钥添加到 Dockerfile 中?
  • 我创建了一次ssh-keys,它被存储在app目录中。我将公钥添加到 Github,完成后,我注释掉了 ssh-keygen 行。我不确定将ssh-keys 添加到我的Dockerfile 是什么意思,但这是我添加ssh-keys 所遵循的一系列步骤。如果我在这里遗漏了什么,请告诉我。

标签: git docker ssh bundler git-clone


【解决方案1】:

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

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

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

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

另见“How to cache bundle install with Docker

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

【讨论】:

  • 我在交互模式下复制了文件,但似乎效果不佳。我发现在修改父图像后,我也必须提交更改。感谢您的帮助!
猜你喜欢
  • 2018-03-11
  • 1970-01-01
  • 1970-01-01
  • 2020-12-08
  • 2021-08-04
  • 1970-01-01
  • 2015-05-16
  • 2014-05-18
  • 2018-06-11
相关资源
最近更新 更多