gpt4 book ai didi

image - dockerfile 中的 AS 基础和 AS 构建有什么区别?

转载 作者:行者123 更新时间:2023-12-02 18:47:59 26 4
gpt4 key购买 nike

我想知道FROM mcr.microsoft.com/dotnet/core/aspnet:2.1-stretch-slim AS base的区别和 FROM mcr.microsoft.com/dotnet/core/sdk:2.1-stretch AS build .你能解释一下AS base之间的区别吗?和 AS build ?
这是默认值 dockerfile由 Visual Studio 生成:

FROM mcr.microsoft.com/dotnet/core/aspnet:2.1-stretch-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/core/sdk:2.1-stretch AS build
WORKDIR /src
COPY ["WebApplication1/WebApplication1.csproj", "WebApplication1/"]
RUN dotnet restore "WebApplication1/WebApplication1.csproj"
COPY . .
WORKDIR "/src/WebApplication1"
RUN dotnet build "WebApplication1.csproj" -c Release -o /app

FROM build AS publish
RUN dotnet publish "WebApplication1.csproj" -c Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "WebApplication1.dll"]

最佳答案

没有功能差异,它只是构建阶段的名称。在 dockerfile 的这个阶段构建的图像(阶段以 FROM 关键字开始,在下一个 FROM 之前结束)稍后将可以使用该名称访问。

Optionally a name can be given to a new build stage by adding AS name to the FROM instruction. The name can be used in subsequent FROM and COPY --from=<name|index> instructions to refer to the image built in this stage.


  • https://docs.docker.com/engine/reference/builder/#from

  • 例如,姓名 foobar
    FROM image AS foo
    ...
    ...

    FROM foo AS bar
    ...
    ...

    FROM foo
    COPY --from=bar
    它是在 17.05 中为多阶段构建添加的,更多内容是: https://docs.docker.com/develop/develop-images/multistage-build/

    关于image - dockerfile 中的 AS 基础和 AS 构建有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55940378/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com