我有以下 Dockerfile 内容:
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 [email protected] /cdn-cgi/l/email-protection:silentdata/cdtc-identity-service.git
WORKDIR cdtc-identity-service
RUN pipenv install
CMD python service_test.py
构建图像,我得到以下输出:
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
Why the git
第二次找不到命令?
多阶段构建不会将多个图像合并在一起。它们允许您构建多个 docker 映像,并为您提供有用的语法来在这些映像之间复制工件。合并映像将是一项不平凡的任务(某些命令会修改文件而不是创建文件,例如包管理数据库,因此即使两个兼容的映像也会给最终用户带来问题)。
对于您的用例,您可能希望选择最合适的基础映像并在那里安装您的工具、代码、编译的应用程序。一旦你开始工作,就可以添加一个新的最小版本的阶段。
有关多阶段构建的更多信息,请参阅:https://docs.docker.com/develop/develop-images/multistage-build/ https://docs.docker.com/develop/develop-images/multistage-build/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)