Docker Support in Visual Studio 2017
Friday, July 14, 2017 at 12:31PM
lessCode

Having experimented with Docker on Windows about a year ago (on a Technical Preview of Windows Server 2016), I thought I’d take a quick look at how container support has evolved with the latest version of the operating system and dev tools. At the time the integration of Docker into Windows was fairly flaky (to be expected for such a bleeding edge technology), but I was able to get a relatively large Windows-dependent monolith to run inside a set of Windows Containers. Most of this involved crafting Dockerfiles and running docker commands manually (and eventually scripting these commands to automate the build process).

Docker tools are now included in Visual Studio, so you can enable Docker support in a new (web) project when you create it:

image

Alternatively, you can add Docker support after the fact from the project context menu:

image

Either way, you get the following:

The first time you run, there’s a significant delay while the appropriate image files are downloaded, but this is a one-time hit.

Your service image contains a CLR debugger, which Visual Studio can hook up to, so you can step through your service code.

What’s interesting (and not a little surprising) is that if you’re targeting .NET Core, your image will target a Linux base image by default. Docker for Windows also defaults to running containers in a Linux Hyper-V VM, so when you hit F5 the container will run your .NET Core service on Linux, and you’ll be remote debugging into a Linux machine.

All very cool stuff, and works well right out of the box without too much fuss. Of course, you can also do all of this manually from the command-line if you prefer to develop in a lightweight editor like VSCode.

Article originally appeared on lesscode.net (http://www.lesscode.net/).
See website for complete article licensing information.