How to build and run ASP.NET Core web app in Docker?

How to build and run ASP.NET Core web app in Docker?

18 February 2021

Build the ASP.NET Core web app

Let’s consider the name of the project is “WebApp”.

Create a docker file similar to the following commands to build the ASP.NET web app.

How_to_build_and_run_ASP_NET_Core_web_app_in_Docker_01

Run the ASP.NET Core web app in Docker container

Add the following commands to run the ASP.NET web app

How_to_build_and_run_ASP_NET_Core_web_app_in_Docker_combine_02

Finally, build and run the docker images

If you want to perform both build and run operation, then make a single docker file containing both dotnet build and run commands.

First, we need to build the docker image as below:

How_to_build_and_run_ASP_NET_Core_web_app_in_Docker_04

We could run it in the local docker container or we could take upload the built image on any cloud containers. Command to run it in the local container.

How_to_build_and_run_ASP_NET_Core_web_app_in_Docker_05

Here we have exposed the docker container’s internal port 80 to local machines port 8080.

You can now access the web app on http://localhost:8080/

Please refer to the Docker and Microsoft documentation for writing more custom docker file:
https://docs.docker.com/

https://docs.microsoft.com/en-us/dotnet/core/docker/introduction

search
Blog Categories
Request a quote