Visual Studio 2017 makes it very easy to start using Docker containers to run your ASP.NET Core projects. It used to be an elaborate set of command line instructions, not knowing exactly what was happing and getting stuck whenever a build, deployment or run would fail somewhere down the line.
With VS 2017 it seems like most of that behind the scenes magic is conveniently hidden and automated. That may mean that if it still fails, for some reason, it’s not easy to trace down the issue. However, under normal circumstances, this is less likely to happen.
To use Docker containers, you first need to install Docker for Windows, here: https://docs.docker.com/docker-for-windows/
During the installation, you may receive the message indicating that Hyper-V features need to be installed. The installer takes care of that, but it may take a few minutes doing so and there’s little feedback that it’s actually installing. The machine will need to reboot after installation. After the restart, check that Docker is indeed running.
Before you start your first new ASP.NET Core project in Visual Studio 2017, make sure you configure a shared drive in Docker. Go to Docker Settings > Shared Drives.
The shared drive should be the one where you normally build and deploy your projects. Now it’s time to start Visual Studio 2017. Create a new project and be sure to select the ASP.NET Core Web Application template.
Enabling Docker support is now as easy as checking a box.
That’s it! Click OK to scaffold the project. This may take a few seconds, since a basic ASP.NET web application seems to require quite a few files.
Building and deploying also takes a few moments to complete, but it does work.
For fun, you can check the OS Version Docker is using.
ViewData[“Message”] = System.Runtime.InteropServices.RuntimeInformation.OSDescription;
Linux on Windows. Who would have guessed.