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

我错过了什么?

原文由 dingo_d 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 704
2 个回答

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

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

这些是 3 个单独的命令。

原文由 Kevin Kopf 发布,翻译遵循 CC BY-SA 4.0 许可协议

对于那些使用 alpine 图片的人来说, RUN apk add --no-cache git 对我有用。

原文由 Jairo Lozano 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题