.NET如何创建Dockerfile文件构建镜像?
创建一个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"]
关注我】。(●'◡'●)
如果,您希望更容易地发现我的新博客,不妨点击一下绿色通道的【因为,我的写作热情也离不开您的肯定与支持,感谢您的阅读,我是【Jack_孟】!
本文来自博客园,作者:jack_Meng,转载请注明原文链接:https://www.cnblogs.com/mq0036/p/17956433
【免责声明】本文来自源于网络,如涉及版权或侵权问题,请及时联系我们,我们将第一时间删除或更改!