This article will show you how to run a simple .Net core in a Docker container.

the advantages of running your .NET Core MVC App on a containerised environment are

  • Flexible to deploy
  • Better scalability with the right architecture
  • Enhance resilience with the right architecture

Prerequisites

Where to get the right docker images

Microsoft has created official Docker images and made publicly available on Docker Hub. There are multiple responsitories that you can download and each repository has multiple images with various versions of .NET and OS. Microsoft Docker Hub Repositories

Lets Get Started

Install Docker

First you will need to install docker Desktop on your development machine

Windows 10 Docker Destop

Mac Docker Destop

If you are using Windows 8 or below, you will need to use docker tool box, it can be a little bit tricky so take your time and follow the instructions carefully.

Windows 8 - Docker Toolbox

Running a .NET Console App in Docker

To create a simple console app in a Linux container, open your docker console and run:

docker run --rm microsoft/dotnet-samples

If it ran successfully, The console will return Hello from .NET Core! and an image of a cartoon robot.

Running a .NET MVC Web App in Docker

Type the following command to run a sample web application:

docker run -it --rm -p 8000:80 --name aspnetcore_sample microsoft/dotnet-samples:aspnetapp

To test it, in windows 10 or Mac goto http://localhost:8000 If you are using Docker Toolbox in Windows 8 goto http://192.168.99.100:8000/ Now you should see the sample .NET MVC web app.

.NET mvc app docker

That’s it! you have successfully ran your first .NET MVC app on your local Docker container!