In this blog post, I’ll show you how I use Visual Studio 2017 and Docker to create an ASP.NET Core application and run It Inside a Docker Container directly from VS.
Because .NET Core Is a cross-platform application both Linux and Windows Container are supported.
At the end of this post, you will also see how to add Docker support for existing ASP.NET Core applications.
Visual Studio 2017 And Docker
Announced late last year Visual Studio 2017 and Docker support allows developers and DevOps Engineers to run, test and export .NET Core applications to Docker Containers.
The requirements for Visual Studio 2017 and Docker support are:
- Docker For Windows running on Windows 10 (see How to Install Docker On Windows 10 )
- We must enable Shared Drives by Right clicking on the Docker System’s Tray -> Properties (Linux Containers mode needed) -> Shared Drives
Tick the tick box and click on the apply button.
In the example below, I’ll show you how to create a new ASP.NET Core application with Docker support.
From VS I start a new project (web) and select ASP.NET Core Web Application and click OK
In the application screen, I’ll use the Docker Support option and tick the box and select Windows or Linux Containers
In the Solution, Explorer VS will create the DockerFile and the docker-compose files
And below, I have my DockerFile configured by VS
As you can see below, VS will show the Docker support In the debug menu.
When Debug starts, VS will create a Docker container, load the code and run its code Inside the Container.
Debug with Docker
VS will also start the default browser and open the web application.
Below, you can see my ASP.NET Core application running.
Add Docker Support to Existing applications
You can also add Docker support to the existing ASP.NET Core application simply but right-click on the app from Solution Explorer -> Add -> Docker Support