为什么git --version语句无法识别? [英] Why git --version statement does not get recognize?

查看:82
本文介绍了为什么git --version语句无法识别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下具有内容的Dockerfile:

I have the following Dockerfile with content:

FROM ubuntu:bionic AS os
RUN apt-get update
RUN apt-get install -y git
RUN git --version

FROM node:13.10.1-buster-slim

FROM python:3.7.7-slim-stretch as test
RUN pip install --user pipenv
RUN git --version
RUN git clone git@gitlab.com:silentdata/cdtc-identity-service.git

WORKDIR cdtc-identity-service

RUN pipenv install

CMD python service_test.py

构建图像,我得到以下输出:

Building the image, I've got the following output:

Sending build context to Docker daemon  43.59MB
Step 1/12 : FROM ubuntu:bionic AS os
 ---> 72300a873c2c
Step 2/12 : RUN apt-get update
 ---> Using cache
 ---> 42013f860b31
Step 3/12 : RUN apt-get install -y git
 ---> Using cache
 ---> 8f27d95fcb6e
Step 4/12 : RUN git --version
 ---> Using cache
 ---> ae49a9465233
Step 5/12 : FROM node:13.10.1-buster-slim
 ---> 500c5a190476
Step 6/12 : FROM python:3.7.7-slim-stretch as test
 ---> c9ec5ac0f580
Step 7/12 : RUN pip install --user pipenv
 ---> Using cache
 ---> 3a9358e72deb
Step 8/12 : RUN git --version
 ---> Running in 545659570a84
/bin/sh: 1: git: not found
The command '/bin/sh -c git --version' returned a non-zero code: 127

为什么第二次找不到 git 命令?

Why the git command could not be found at the second time?

推荐答案

多阶段构建不会将多个图像合并在一起.它们允许您构建多个docker映像,并为您提供有用的语法以在这些映像之间复制工件.合并映像将是一项艰巨的任务(某些命令会修改文件而不是创建文件,例如,程序包管理数据库,因此即使两个兼容的映像也会给最终用户带来麻烦).

Multi-stage builds do not merge multiple images together. They allow you to build multiple docker images, and give you a useful syntax to copy artifacts between those images. Merging images would be a non-trivial task (some commands modify files rather than create them, e.g. the package management DB, so even two compatible images would result in issues for the end user).

对于您的用例,您可能希望选择最合适的基础映像,然后在其中安装工具,代码和已编译的应用程序.一旦使它起作用,就可以添加一个用于最小发行版的新阶段.

For your use case, you probably want to pick the most appropriate base image and install your tools, code, compiled app there. Once you've gotten that to work, then adding a new stage for the minimal release can be added on.

有关多阶段构建的更多信息,请参见: https://docs.docker.com/develop/develop-images/multistage-build/

For more on multi-stage builds, see: https://docs.docker.com/develop/develop-images/multistage-build/

这篇关于为什么git --version语句无法识别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆