创建一个WebApi项目,并且创建一个Dockerfile空文件,添加以下代码,7.0代表的你项目使用的SDK的版本,构建的时候也需要选择好指定的镜像tag
- FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
- WORKDIR /app
- EXPOSE 80
- EXPOSE 443
- FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
- ARG BUILD_CONFIGURATION=Release
- WORKDIR /src
- COPY ["WebApplication1/WebApplication1.csproj", "WebApplication1/"]
- RUN dotnet restore "./WebApplication1/./WebApplication1.csproj"
- COPY . .
- WORKDIR "/src/WebApplication1"
- RUN dotnet build "./WebApplication1.csproj" -c $BUILD_CONFIGURATION -o /app/build
- FROM build AS publish
- ARG BUILD_CONFIGURATION=Release
- RUN dotnet publish "./WebApplication1.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
- FROM base AS final
- WORKDIR /app
- COPY --from=publish /app/publish .
- ENTRYPOINT ["dotnet", "WebApplication1.dll"]
- FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
- WORKDIR /app
- EXPOSE 80
- EXPOSE 443
- FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
- ARG BUILD_CONFIGURATION=Release
- WORKDIR /src
- COPY ["WebApplication1/WebApplication1.csproj", "WebApplication1/"]
- RUN dotnet restore "./WebApplication1/./WebApplication1.csproj"
- COPY . .
- WORKDIR "/src/WebApplication1"
- RUN dotnet build "./WebApplication1.csproj" -c $BUILD_CONFIGURATION -o /app/build
- FROM build AS publish
- ARG BUILD_CONFIGURATION=Release
- RUN dotnet publish "./WebApplication1.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
- FROM base AS final
- WORKDIR /app
- COPY --from=publish /app/publish .
- ENTRYPOINT ["dotnet", "WebApplication1.dll"]
出处:https://www.duidaima.com/Group/Topic/ASP.NET/18770
标签:WebApplication1,app,publish,build,dotnet,镜像,NET,Dockerfile From: https://www.cnblogs.com/mq0036/p/17956433