gpt4 book ai didi

git - 通过 Dockerfile 安装包时出错

转载 作者:行者123 更新时间:2023-12-02 20:11:14 25 4
gpt4 key购买 nike

我是 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 key 。当我退出交互模式并再次登录时,有时也会发生同样的情况,当我再次登录时,我新添加的包不会出现。我尝试提交更改,但问题仍然存在。我无法弄清楚为什么会这样。

最佳答案

bundle install 时,这种错误很常见。需要访问私有(private)仓库。
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

关于git - 通过 Dockerfile 安装包时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46710625/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com