How to deploy multi environment with Asp.net Core and Docker

Asp.net Core and Docker for beginners

1. Asp.net Core Environment

You can follow by this article from Microsoft to deeply understand about multi environment for .net core app.

But I can summary here:

  • Asp.net Core provides 3 environment stages: Production Staging and Development
  • Your setting file will be stored at appsettings.{environment}.json
  • We need to set ASPNETCORE_ENVIRONMENT when build the application

Assume our application will have two deploys :

  1. Production with appsettings.Production.json
  2. Staging with appsettings.Staging.json

2. Let start

Assume you have a new app which was created by dotnet new webapi — name dotnet_demo_webapi .

  • Firstly, you need to update Startup.cs file to load .json files.
  • Second, Add yourDockerfile maybe like below:
  • Finally, because we need to build 2 versions (Staging and Production) so we will use docker-compose.yml to manage servies, you can read docks here:

After that run docker-compose up --build -d to build images and run services.

Any questions you can comment below, thanks for reading.

Asp.net Core & Docker example:

https://github.com/jinhduong/dotnet-and-docker