[英]git install fails in Dockerfile
我正在尝试在进行 docker build 时拉出我正在处理的存储库,因此我按照本教程进行操作,因此我添加了我的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
我错过了什么?
你过度分析了这一点。 这只是一个简单的错字。 应该:
RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y git
这些是 3 个单独的命令。
一些想法:
apt-get install --assume-yes git
替换apt-get install git
apt-get install --assume-yes git
。 如果没有--assume-yes
它会提示您进行确认,您无法给出确认,并且它会很聪明地弄清楚并假设您的意思是“否”。0600
。 我只想复制它,特别是chmod 0600 ~/.ssh/id_rsa
以确保。总的来说,你的 Dockerfile 看起来非常聪明,我从阅读中得到了一些新的想法。
对于那些使用alpine
图像的人, RUN apk add --no-cache git
帮我解决了这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.