saiprashanthpantula / Asp.net-MVC-5

A Sample Asp.Net MVC 5.0 App with Docker Container for deployment.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ASP.NET MVC Docker Sample

This sample demonstrates how to use ASP.NET MVC and Docker together. See ASP.NET Docker Sample and .NET Framework Console Docker Sample for using Docker in other scenarios.

The sample builds the application in a container based on the larger .NET Framework SDK Docker image. It builds the application and then copies the final build result into a Docker image based on the smaller ASP.NET Runtime Docker image. It uses Docker multi-stage build and multi-arch tags.

This sample requires Docker 17.06 or later of the Docker client.

Try a pre-built ASP.NET Docker Image

You can quickly run a container with a pre-built sample ASP.NET Docker image, based on the ASP.NET Docker sample.

Type the following Docker command:

docker run --name aspnet_sample --rm -it -p 8000:80 mcr.microsoft.com/dotnet/framework/samples:aspnetapp

After the application starts, navigate to http://localhost:8000 in your web browser. You need to navigate to the application via IP address instead of localhost for earlier Windows versions, which is demonstrated in View the ASP.NET app in a running container on Windows.

Getting the sample

The easiest way to get the sample is by cloning the samples repository with git, using the following instructions:

git clone https://github.com/microsoft/dotnet-framework-docker/

You can also download the repository as a zip.

Build and run the sample with Docker

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.

cd samples
cd aspnetmvcapp
docker build --pull -t aspnetmvcapp .
docker run --name aspnetmvc_sample --rm -it -p 8000:80 aspnetmvcapp

You should see the following console output as the application starts.

C:\git\dotnet-framework-docker\samples\aspnetapp>docker run --name aspnetmvc_sample --rm -it -p 8000:80 aspnetmvcapp
Service 'w3svc' has been stopped

Service 'w3svc' started

After the application starts, navigate to http://localhost:8000 in your web browser. You need to navigate to the application via IP address instead of localhost for earlier Windows versions, which is demonstrated in View the ASP.NET app in a running container on Windows.

Note: The -p argument maps port 8000 on your local machine to port 80 in the container (the form of the port mapping is host:container). See the Docker run reference for more information on commandline parameters.

View the ASP.NET app in a running container on Windows

After the application starts, navigate to the container IP (as opposed to http://localhost) in your web browser with the the following instructions:

  1. Open up another command prompt.
  2. Run docker exec aspnetmvc_sample ipconfig.
  3. Copy the container IP address and paste into your browser (for example, 172.29.245.43).

See the following example of how to get the IP address of a running Windows container.

C:\git\dotnet-framework-docker\samples\aspnetmvcapp>docker exec aspnetmvc_sample ipconfig

Windows IP Configuration


Ethernet adapter Ethernet:

   Connection-specific DNS Suffix  . : contoso.com
   Link-local IPv6 Address . . . . . : fe80::1967:6598:124:cfa3%4
   IPv4 Address. . . . . . . . . . . : 172.29.245.43
   Subnet Mask . . . . . . . . . . . : 255.255.240.0
   Default Gateway . . . . . . . . . : 172.29.240.1

Note: docker exec supports identifying containers with name or hash. The container name is used in the preceding instructions. docker exec runs a new command (as opposed to the entrypoint) in a running container.

Some people prefer using docker inspect for this same purpose, as demonstrated in the following example.

C:\git\dotnet-framework-docker\samples\aspnetmvcapp>docker inspect -f "{{ .NetworkSettings.Networks.nat.IPAddress }}" aspnetcore_sample
172.25.157.148

.NET Resources

More Samples

Docs and More Information:

Related Docker Hub Repos

.NET Framework:

.NET Core:

About

A Sample Asp.Net MVC 5.0 App with Docker Container for deployment.


Languages

Language:JavaScript 49.1%Language:C# 26.9%Language:HTML 18.7%Language:CSS 2.4%Language:Dockerfile 2.4%Language:ASP 0.5%