首页 > 解决方案 > Dockerfile 中的 git install 失败

问题描述

我正在尝试在进行 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 install 阶段出错

E:更新命令不带参数

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

我错过了什么?

标签: gitdocker

解决方案


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

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

这些是 3 个单独的命令。


推荐阅读