The aspnetapp sample demonstrates how to Dockerize an ASP.NET Core app. If you'd like to see how to Dockerize a .NET Framework app check out the .NET Framework Docker samples.
The instructions assume that you already have .NET Core 1.1, Git, and Docker clients installed. They also assume you already know how to target Linux or Windows containers. Do try both image types. You need the latest Windows 10 or Windows Server 2016 to use Windows containers. For additional tutorials on ASP.NET Core see ASP.NET Core Getting Started.
First, prepare your environment by cloning the repository and navigating to the sample:
git clone https://github.com/dotnet/dotnet-docker-samples/
cd dotnet-docker-samples/aspnetapp
Follow these steps to run the sample locally:
dotnet restore
dotnet run
Follow these steps to run this sample in a Linux container:
dotnet publish -o published
docker build -t aspnetapp .
docker run -d -p 80:80 aspnetapp
Follow these steps to run this sample in a Windows container:
dotnet publish -o published
docker build -t aspnetapp -f Dockerfile.nano .
docker run -d -p 80:80 aspnetapp
- If you are using a linux container you can simply browse to http://localhost:80 to access your app in a web browser.
- If you are using the Nano Windows Container there is currently a bug that affects how Windows 10 talks to Containers via "NAT" (Network Address Translation). Today you must hit the IP of the container directly. You can get the IP address of your container with the following steps:
- Run
docker ps
and copy the hash of your container ID - Run
docker inspect -f "{{ .NetworkSettings.Networks.nat.IPAddress }}" HASH
whereHASH
is replaced with your container ID. - Copy the container ip address and paste into your browser with port 80. (Ex: 172.16.240.197:80)
- Run