From 03003f72b6fc1b1dd0af7614de25d79b18aff3cb Mon Sep 17 00:00:00 2001 From: avichalchum <46034716+avichalchum@users.noreply.github.com> Date: Wed, 27 May 2020 12:26:44 -0500 Subject: [PATCH 1/4] Update dotnetcore.md Adding an example for .Net Core docker files as consumed by build agents and recommended by Microsoft best practices. --- engine/examples/dotnetcore.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/engine/examples/dotnetcore.md b/engine/examples/dotnetcore.md index df7a1eec3aca..c537d62ea9a1 100644 --- a/engine/examples/dotnetcore.md +++ b/engine/examples/dotnetcore.md @@ -31,6 +31,8 @@ tutorial](https://www.asp.net/get-started) to initialize a project or clone our ## Create a Dockerfile for an ASP.NET Core application +### Method 1: + 1. Create a `Dockerfile` in your project folder. 2. Add the text below to your `Dockerfile` for either Linux or [Windows Containers](https://docs.microsoft.com/virtualization/windowscontainers/about/). @@ -68,7 +70,29 @@ ENTRYPOINT ["dotnet", "aspnetapp.dll"] bin\ obj\ ``` +### Method 2 (CI recommended method): +1. Create a `Dockerfile` in your project folder. +2. Add the text below to your `Dockerfile` for either Linux or [Windows + Containers](https://docs.microsoft.com/virtualization/windowscontainers/about/). + The tags below are multi-arch meaning they pull either Windows or + Linux containers depending on what mode is set in + [Docker Desktop for Windows](../../docker-for-windows/index.md). Read more on + [switching containers](../../docker-for-windows/index.md#switch-between-windows-and-linux-containers). +3. The `Dockerfile` assumes that your application is called `aspnetapp`. Change the `Dockerfile` to use the DLL file of your project. This method assumes that your project is already built and copies over the build artifacts from the publish folder. Refer to the Microsoft documentation on [Containerize a .Net Core app](https://docs.microsoft.com/en-us/dotnet/core/docker/build-container?tabs=windows#create-the-dockerfile). +The docker build step will be much faster than method 1, as all the artifacts are built outside of docker build step and the size of the base image is much smaller as compared to the build base image. +This method is preferred for CI tools like Jenkins, Azure DevOps, GitLab CI, e.t.c. as you can use the same artifacts in multiple deployment models if Docker Containers isn't the only deployment model being used. Addittionally, you'll be able to run unit tests and publish code coverage reports or use custom plugins on the artifacts built by the CI. + +```dockerfile +FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 +COPY bin/Release/netcoreapp3.1/publish/ App/ +WORKDIR /App +ENTRYPOINT ["dotnet", "aspnetapp.dll"] +``` +4. To make your build context as small as possible add a [`.dockerignore` + file](/engine/reference/builder/#dockerignore-file) + to your project folder. + ## Build and run the Docker image 1. Open a command prompt and navigate to your project folder. From b44d1f555dac2d89002a23b93e99dcd52e3acf04 Mon Sep 17 00:00:00 2001 From: avichalchum <46034716+avichalchum@users.noreply.github.com> Date: Thu, 3 Dec 2020 09:50:18 -0600 Subject: [PATCH 2/4] Update engine/examples/dotnetcore.md Co-authored-by: Guillaume Tardif --- engine/examples/dotnetcore.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/examples/dotnetcore.md b/engine/examples/dotnetcore.md index c537d62ea9a1..89e380b3ca90 100644 --- a/engine/examples/dotnetcore.md +++ b/engine/examples/dotnetcore.md @@ -70,7 +70,7 @@ ENTRYPOINT ["dotnet", "aspnetapp.dll"] bin\ obj\ ``` -### Method 2 (CI recommended method): +### Method 2 (build app outside Docker container): 1. Create a `Dockerfile` in your project folder. 2. Add the text below to your `Dockerfile` for either Linux or [Windows From 67f228a62e6ef6a2c00e75f489a03adb5c62e866 Mon Sep 17 00:00:00 2001 From: Usha Mandya <47779042+usha-mandya@users.noreply.github.com> Date: Tue, 8 Dec 2020 10:13:56 +0000 Subject: [PATCH 3/4] Format updates --- engine/examples/dotnetcore.md | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/engine/examples/dotnetcore.md b/engine/examples/dotnetcore.md index 89e380b3ca90..92e1a4ccc856 100644 --- a/engine/examples/dotnetcore.md +++ b/engine/examples/dotnetcore.md @@ -79,16 +79,19 @@ obj\ Linux containers depending on what mode is set in [Docker Desktop for Windows](../../docker-for-windows/index.md). Read more on [switching containers](../../docker-for-windows/index.md#switch-between-windows-and-linux-containers). -3. The `Dockerfile` assumes that your application is called `aspnetapp`. Change the `Dockerfile` to use the DLL file of your project. This method assumes that your project is already built and copies over the build artifacts from the publish folder. Refer to the Microsoft documentation on [Containerize a .Net Core app](https://docs.microsoft.com/en-us/dotnet/core/docker/build-container?tabs=windows#create-the-dockerfile). -The docker build step will be much faster than method 1, as all the artifacts are built outside of docker build step and the size of the base image is much smaller as compared to the build base image. -This method is preferred for CI tools like Jenkins, Azure DevOps, GitLab CI, e.t.c. as you can use the same artifacts in multiple deployment models if Docker Containers isn't the only deployment model being used. Addittionally, you'll be able to run unit tests and publish code coverage reports or use custom plugins on the artifacts built by the CI. +3. The `Dockerfile` assumes that your application is called `aspnetapp`. Change the `Dockerfile` to use the DLL file of your project. This method assumes that your project is already built and it copies the build artifacts from the publish folder. Refer to the Microsoft documentation on [Containerize a .Net Core app](https://docs.microsoft.com/en-us/dotnet/core/docker/build-container?tabs=windows#create-the-dockerfile){: target="blank" rel="noopener" class=“"}. -```dockerfile -FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 -COPY bin/Release/netcoreapp3.1/publish/ App/ -WORKDIR /App -ENTRYPOINT ["dotnet", "aspnetapp.dll"] -``` + The `docker build` step here will be much faster than method 1, as all the artifacts are built outside of the `docker build` step and the size of the base image is much smaller compared to the build base image. + + This method is preferred for CI tools like Jenkins, Azure DevOps, GitLab CI, etc. as you can use the same artifacts in multiple deployment models if Docker isn't the only deployment model being used. Addittionally, you'll be able to run unit tests and publish code coverage reports, or use custom plugins on the artifacts built by the CI. + + ```dockerfile + FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 + COPY bin/Release/netcoreapp3.1/publish/ App/ + WORKDIR /App + ENTRYPOINT ["dotnet", "aspnetapp.dll"] + ``` + 4. To make your build context as small as possible add a [`.dockerignore` file](/engine/reference/builder/#dockerignore-file) to your project folder. From 45d4bb9fabec64931546b435f9937d10962ccd86 Mon Sep 17 00:00:00 2001 From: Usha Mandya <47779042+usha-mandya@users.noreply.github.com> Date: Tue, 8 Dec 2020 11:11:38 +0000 Subject: [PATCH 4/4] Update dotnetcore.md --- engine/examples/dotnetcore.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/engine/examples/dotnetcore.md b/engine/examples/dotnetcore.md index 92e1a4ccc856..3e6188337abb 100644 --- a/engine/examples/dotnetcore.md +++ b/engine/examples/dotnetcore.md @@ -81,16 +81,16 @@ obj\ [switching containers](../../docker-for-windows/index.md#switch-between-windows-and-linux-containers). 3. The `Dockerfile` assumes that your application is called `aspnetapp`. Change the `Dockerfile` to use the DLL file of your project. This method assumes that your project is already built and it copies the build artifacts from the publish folder. Refer to the Microsoft documentation on [Containerize a .Net Core app](https://docs.microsoft.com/en-us/dotnet/core/docker/build-container?tabs=windows#create-the-dockerfile){: target="blank" rel="noopener" class=“"}. - The `docker build` step here will be much faster than method 1, as all the artifacts are built outside of the `docker build` step and the size of the base image is much smaller compared to the build base image. + The `docker build` step here will be much faster than method 1, as all the artifacts are built outside of the `docker build` step and the size of the base image is much smaller compared to the build base image. - This method is preferred for CI tools like Jenkins, Azure DevOps, GitLab CI, etc. as you can use the same artifacts in multiple deployment models if Docker isn't the only deployment model being used. Addittionally, you'll be able to run unit tests and publish code coverage reports, or use custom plugins on the artifacts built by the CI. + This method is preferred for CI tools like Jenkins, Azure DevOps, GitLab CI, etc. as you can use the same artifacts in multiple deployment models if Docker isn't the only deployment model being used. Addittionally, you'll be able to run unit tests and publish code coverage reports, or use custom plugins on the artifacts built by the CI. - ```dockerfile - FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 - COPY bin/Release/netcoreapp3.1/publish/ App/ - WORKDIR /App - ENTRYPOINT ["dotnet", "aspnetapp.dll"] - ``` + ```dockerfile + FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 + COPY bin/Release/netcoreapp3.1/publish/ App/ + WORKDIR /App + ENTRYPOINT ["dotnet", "aspnetapp.dll"] + ``` 4. To make your build context as small as possible add a [`.dockerignore` file](/engine/reference/builder/#dockerignore-file)