This Dockerfile uses a multi-stage build process to create a.NET Core image by first building the application with Mono and then building the.NET Core image with ASP.NET Core. The final image includes the published application files and exposes port 80 for the container to run.
#FROM mono:latest
#RUN mono --version
#RUN ls -la
#ADD ./subscription.services /home/src
#ADD ./act.subscription.management.sln /home/src
#WORKDIR /home/src
#RUN msbuild ./subscription.services/Subscription.Services.EloquaImport/Subscription.Services.EloquaImport.csproj
#RUN mono Subscription.Services.EloquaImport.exe
#FROM microsoft/aspnetcore:1.1
FROM microsoft/aspnetcore-build:1.0-1.1
ARG source
EXPOSE 80
WORKDIR /app/src
ADD ./*.sln /app/src/
ADD ./subscription.services/Subscription.Services.EloquaImport/*.csproj /app/src/subscription.services/Subscription.Services.EloquaImport/
ADD ./subscription.services/Subscription.Services.ZuoraExport/*.csproj /app/src/subscription.services/Subscription.Services.ZuoraExport/
ADD ./*.dcproj /app/src/
RUN /bin/bash -c "dotnet restore ./act.subscription.management.sln"
ADD . /app/src
RUN /bin/bash -c "dotnet restore ./act.subscription.management.sln && dotnet publish ./act.subscription.management.sln -c Release -o ./obj/Docker/publish"
RUN cp -R ${source:-subscription.services/Subscription.Services.EloquaImport/obj/Docker/publish} /app
WORKDIR /app/publish
EXPOSE 80
ENTRYPOINT ["/usr/bin/dotnet", "/app/publish/Subscription.Services.EloquaImport.dll"]
# Define the base image and set the working directory
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
WORKDIR /app
# Install the necessary package for.NET Core
RUN dotnet install-template
# Copy the project files into the current directory
COPY./subscription.services/Subscription.Services.EloquaImport/*.csproj./subscription.services/Subscription.Services.EloquaImport/
COPY./subscription.services/Subscription.Services.ZuoraExport/*.csproj./subscription.services/Subscription.Services.ZuoraExport/
COPY./act.subscription.management.sln./act.subscription.management.sln
# Restore the NuGet packages
RUN /bin/bash -c "dotnet restore./act.subscription.management.sln"
# Copy the rest of the application files into the current directory
COPY..
# Build the application
RUN /bin/bash -c "dotnet publish./act.subscription.management.sln -c Release -o./obj/Docker/publish"
# Create a new image with the published application
FROM mcr.microsoft.com/dotnet/core/runtime:3.1
WORKDIR /app
COPY --from=build-env /app/obj/Docker/publish.
EXPOSE 80
ENTRYPOINT ["/usr/bin/dotnet", "Subscription.Services.EloquaImport.dll"]
# You can specify a custom file path for the source directory
# ARG source=${PWD}
# RUN cp -R "${source:-subscription.services/Subscription.Services.EloquaImport/obj/Docker/publish}" /app
# The mono images are not required for.NET Core applications
# FROM mono:latest
# RUN mono --version
# RUN ls -la
Dockerfile Breakdown
This Dockerfile is used to build a multi-stage image for a.NET Core application.
FROM mono:latest
: Uses the latest Mono image as a base.RUN mono --version
: Runs a command to check the Mono version.RUN ls -la
: Runs a command to list the current directory in detail.ADD
statements: Copies files from the current directory to the image.WORKDIR
statement: Sets the working directory to /home/src
.RUN
statements: Builds and runs the application using MSBuild and Mono.FROM microsoft/aspnetcore-build:1.0-1.1
: Uses the ASP.NET Core build image as a base.ARG source
: Sets an argument source
which can be used to specify the path to the application.EXPOSE 80
: Exposes port 80 for the container.WORKDIR
statement: Sets the working directory to /app/src
.ADD
statements: Copies the solution file and project files to the image.RUN
statements: Restores and publishes the application using dotnet
.RUN
statements: Copies the published application files to the final image.WORKDIR
statement: Sets the working directory to /app/publish
.EXPOSE 80
: Exposes port 80 for the container.ENTRYPOINT
statement: Specifies the command to run when the container starts.