This sample demonstrates how to use ASP.NET Core MVC and Docker together.
This sample requires Docker 17.06 or later of the Docker client.
Note: original source code copied (with permission) from SecuringAspNetCore2WithOAuth2AndOIDC. Projects then dockerized by Christian Crowhurst
You can quickly run a container with a pre-built sample ASP.NET Core Docker image.
- Download / browse to directory containing docker-compose.yml
- Open a powershell prompt in the directory containing the
docker-compose.yml
- In the same powershell prompt run:
docker-compose -p aspnetcore-sample up -d
To browse to the home page of the web app now running in a container:
- Get the IP address of the container
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' (docker ps -f name=aspnetcore-sample_web-app_1 -q)
- Open a browser and navigate to the IP address
To cleanup:
docker-compose -p aspnetcore-sample down
The easiest way to get the sample is by cloning the samples repository with git, using the following instructions:
git clone https://github.com/christianacca/docker-aspnetcore-sample.git
You can build and run the sample in Docker using the following commands. The instructions assume that you are in the root of the repository.
.\build.ps1 Build, UpDev
The above command ultimately:
- builds a new image
christianacca/aspnetappcore-sample
from code in thesrc/
directory - uses
docker-compose up
to start the web app and it's associated database inside containers - open a browser window (chrome) and navigates to the home page of the web app