与dockerfile中的AS base和AS build有什么区别?

问题描述 投票:0回答:1

我想知道“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之间的区别吗?

这是visual studio生成的默认dockerfile:

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"]
image docker dockerfile
1个回答
0
投票

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

(可选)通过将AS名称添加到FROM指令,可以将名称赋予新的构建阶段。该名称可用于后续的FROM和COPY --from =指令,以引用此阶段构建的图像。 - 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/

© www.soinside.com 2019 - 2024. All rights reserved.