Docker File Sample Flashcards
Pull ASP.NET Core 3.1 runtime and give the name ‘base’
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS base
Set the ports where the container listens at runtime
EXPOSE 80
EXPOSE 443
Pull the ASP.NET Core 3.1 SDK and give the name ‘build’
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
What is the WORKDIR instruction?
The WORKDIR instruction sets the working directory for any RUN, CMD, ENTRYPOINT, COPY and ADD instructions that follow
Set the Working Dir to ‘/src’.
This is where the source code is.
WORKDIR /src
Copy projects
COPY [“Name.Of.Your.Project.csproj”, “Name.Of.Your.Project/”]
COPY [“Dependancy.Of.Your.Project.csproj”, “Dependancy.Of.Your.Project/”]
Run the application in a shell, in this case run ‘dotnet restore’
RUN dotnet restore “Name.Of.Your.Project/”Name.Of.Your.Project.csproj”
WORKDIR “/src/”Name.Of.Your.Project”
COPY . .
RUN dotnet build “Name.Of.Your.Project.csproj” -c Release -o /app/build
Run the publish command using the SDK named as ‘build’
FROM build AS publish
RUN dotnet publish “Name.Of.Your.Project.csproj” -c Release -o /app/publish
Pull ‘base’ image and name it as ‘final’ to allow pull access for publish
FROM base AS final
WORKDIR /app
COPY –from=publish /app/publish .
Set the entry point, in other words, what to run!
ENTRYPOINT [“dotnet”, “Name.Of.Your.Project.dll”]