git install 在 Dockerfile 中失败



我在做 docker 构建时尝试拉取我正在处理的存储库,所以我按照本教程做了,所以我添加了我的Dockerfile

# this is our first build stage, it will not persist in the final image
FROM ubuntu as intermediate
# install git
RUN apt-get update 
apt-get upgrade 
apt-get install git
# add credentials on build
RUN mkdir ~/.ssh && ln -s /run/secrets/host_ssh_key ~/.ssh/id_rsa
# make sure your domain is accepted
RUN touch /root/.ssh/known_hosts
RUN ssh-keyscan github.org >> /root/.ssh/known_hosts
RUN git clone git@github.com:my-repo/myproject.git
FROM ubuntu
# copy the repository form the previous image
COPY --from=intermediate /your-repo /srv/your-repo

在我的docker-compose.yml我添加了

secrets:
host_ssh_key:
file: ~/.ssh/id_rsa

我正在添加

secrets:
- host_ssh_key

在其中一个服务中。

由于这仅供我在本地使用(我不打算将其部署或用于生产,我只是想测试一下(因此可以这样使用它 - 如果它可以工作,因为当前构建在 git 安装阶段失败并出现错误

E:update 命令不带任何参数

错误:服务"web"无法构建:命令"/bin/sh -c apt-get update apt-get upgrade apt-get install git"返回非零代码:100

我错过了什么?

你过度分析了这一点。这只是一个简单的错字。应该是:

RUN apt-get update && 
apt-get upgrade -y && 
apt-get install -y git

这些是 3 个单独的命令。

对于那些使用alpine图像的人来说,RUN apk add --no-cache git为我做了这个技巧。

一些想法:

    1. apt-get install git替换为apt-get install --assume-yes git。 如果没有--assume-yes它会提示您进行确认,您无法给出,并且它会足够聪明地弄清楚并假设您的意思是"不"。
    1. 您添加了 ssh 密钥,但是否确认它0600。 我只会复制它,特别是chmod 0600 ~/.ssh/id_rsa可以肯定的。

总的来说,你的Dockerfile看起来非常聪明,我从阅读中得到了一些新鲜的想法。

最新更新