Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions engine/examples/dotnetcore.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/).
Expand Down Expand Up @@ -68,7 +70,32 @@ ENTRYPOINT ["dotnet", "aspnetapp.dll"]
bin\
obj\
```
### 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
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 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.

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.

## Build and run the Docker image

1. Open a command prompt and navigate to your project folder.
Expand Down