Wednesday, July 21, 2021

Sample Docker files for a simple .net core web application

 Official Docker file as given here

    # syntax=docker/dockerfile:1
    FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build-env
    WORKDIR /app
    
    # Copy csproj and restore as distinct layers
    COPY *.csproj ./
    RUN dotnet restore
    
    # Copy everything else and build
    COPY ../engine/examples ./
    RUN dotnet publish -c Release -o out
    
    # Build runtime image
    FROM mcr.microsoft.com/dotnet/aspnet:3.1
    WORKDIR /app
    COPY --from=build-env /app/out .
    ENTRYPOINT ["dotnet""aspnetapp.dll"]


Docker file generated by Visual Studio: 

  #See https://aka.ms/containerfastmode to 
    #understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

    FROM mcr.microsoft.com/dotnet/aspnet:3.1 AS base
    WORKDIR /app
    EXPOSE 80
    EXPOSE 443
    
    FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
    WORKDIR /src
    COPY ["WebApplication1.csproj""."]
    RUN dotnet restore "./WebApplication1.csproj"
    COPY . .
    WORKDIR "/src/."
    RUN dotnet build "WebApplication1.csproj" -c Release -o /app/build
    
    FROM build AS publish
    RUN dotnet publish "WebApplication1.csproj" -c Release -o /app/publish
    
    FROM base AS final
    WORKDIR /app
    COPY --from=publish /app/publish .
    ENTRYPOINT ["dotnet""WebApplication1.dll"]


Docker file as seen here

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim-arm64v8 AS base
    WORKDIR /app
    EXPOSE 80
    EXPOSE 443
    
    FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
    WORKDIR /src
    COPY ["WhatzThat.Web.csproj""WhatzThat.Web/"]
    RUN dotnet restore "WhatzThat.Web/WhatzThat.Web.csproj" -r linux-arm64
    
    WORKDIR "/src/WhatzThat.Web"
    COPY . .
    
    RUN dotnet build "WhatzThat.Web.csproj" -c Release -o /app/build
    
    FROM build AS publish
    RUN dotnet publish "WhatzThat.Web.csproj" -c Release -o /app/publish -r linux-arm64 --self-contained false --no-restore
    
    FROM base AS final
    WORKDIR /app
    COPY --from=publish /app/publish .
    ENTRYPOINT ["dotnet""WhatzThat.Web.dll"]


No comments:

Post a Comment

How to check local and global angular versions

 Use the command ng version (or ng v ) to find the version of Angular CLI in the current folder. Run it outside of the Angular project, to f...