2017-10-12 226 views
1

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

这里是我的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命令,但我也有类似的错误。请帮我解决这个问题,现在我已经被阻止了一段时间。

此外,当我在进行一些更改后构建图像时,ssh-keys不再出现在泊坞窗图像上。当我退出交互模式并再次登录时,同样的情况发生,当我再次登录时,我新添加的软件包不会显示出来。我尝试了改变,但问题仍然存在。我无法弄清楚为什么会发生这种情况。

+0

我假设你正在使用'SSH键在您的github访问。但是我没有看到你将SSH密钥添加到Dockerfile中? –

+0

我创建了'ssh-keys'一次,它存储在app目录中。我将公钥添加到Github,完成之后,我将'ssh-keygen'行注释掉了。我不知道你的意思是把'ssh-keys'加入到我的Dockerfile中,但是这是我添加'ssh-keys'所遵循的一系列步骤。请让我知道,如果我在这里失去了一些东西。 – frank

回答

0

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

+0

我以交互模式复制了这些文件,但这似乎并不奏效。我发现在修改父图像后,我还必须提交更改。谢谢您的帮助! – frank