Scott Hanselman

Developing on Docker with the new and improved Visual Studio Container Tools (and WSL2)

May 20, 2020 Comment on this post [6] Posted in Docker | VS2019
Sponsored By

I've been spending a lot of time with Docker lately. Docker Desktop on Windows is great and getting better every day. Now that WSL2 (Windows Subsystem for Linux) is rolling out stable over the coming weeks and Docker Desktop supports WSL to host Linux containers directly, I'm finding myself using Visual Studio to develop my sites under Docker.

Visual Studio Container Tools are actively improving as well and the latest release is pretty sweet. You likely already HAVE this as the Containers tool window is now included in Visual Studio 2019 starting with version 16.4 Preview 2 and above!

NOTE: Be sure to check out the Visual Studio Code Docker Extension as well!

First thing that is impressive is that Visual Studio now tries to help you get to a successful place with helpful guidance, as sometimes set up can be daunting.

When you create or open a Docker-enabled project:

  • VS container tools help you install Docker Desktop
  • VS container tools make sure Docker Desktop is running

Start Docker Desktop?

You've got the Container Tools already if you've installed the Web or Azure Workload in Visual Studio 2019 and it is included in the free Visual Studio 2019 Community!

You can Docker-enable a project with a checkbox when you create it OR you can right click Add Docker Support after the fact.

Enable Docker Support

When working with .NET Core the Container Tools will make a great multi-stage Dockerfile that encapsulates best practices. It uses Docker layering to build within Docker using the .NET SDK but then publishing into a smaller runtime container for the smallest possible resulting image for maximum density.

Multistage Dockerfile

Multi-container Debugging

Debugging real systems with multiple containers has been a challenge in the past. VS2019 now has Container Orchestrator Support built-in. This screenshot shows Docker Compose appearing itself as a Debug Target within the standard VS2019 toolbar!

Docker Compose

Once you have a bunch of containers running, the Containers Tool finds a nice balance between showing you the text logs and getting out of your way but also giving you a GUI to start and stop and manage multiple running containers.

You can see below the images I have, the Solution Containers. I can even right click and Attach to Process within a running Linux container! Again, all using WSL2 and wicked fast.

Docker Container Tools

Coming soon to Visual Studio! Native WSL2 debugging

I like my containers BUT if you just want to dev on Linux directly (no containers) then this is one of the "coming soons" that you'll be the most excited about - WSL 2 Debugging! Coming soon to the Marketplace as a preview with a plan to ship in future Visual Studio tooling releases, you'll be able to just select WSL2 (Linux) as a compilation and debug target! That means dev/test/run native Linux on Windows right from VS.

Remember that WSL2 uses a real Linux kernel so there's no emulators here. The WSL2 Linux starts up in about a second and you'll be debugging FAST. WSL2 is rolling out now!

WSL2 in Visual Studio

That means breakpoints and full debugging on Linux from Visual Studio 2019 on Windows. Scott Hunter and I talked about this and showed a demo in our "Journey to One .NET" talk at BUILD this year that you can watch free here!

If you want all these nice Container Tools either install VS2019 or just run the Visual Studio Installer and UPDATE your existing installation.


Sponsor: This week's sponsor is...me! This blog and my podcast has been a labor of love for over 18 years. Your sponsorship pays my hosting bills for both AND allows me to buy gadgets to review AND the occasional taco. Join me!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service
May 28, 2020 11:59
Looks like it's very easy to use containers in VS. But I'm waiting for WSL 2 Debugging, to start migrating my development environment to WSL 2.
May 28, 2020 16:37
Will there be possibility to not only run/debug our apps using docker but also run unit tests? Running tests was the last piece that I didn't find a solution for to run them with containers but also with decent UI. If this is possible then we can finally forget about installing .net core sdks on our developer machines and have sdk upgrades as simple as changing the version in dockerfile, commmit & push. I hope we'll get there one day
May 28, 2020 22:21
...WSL 2 Debugging! Coming soon to the Marketplace as a preview with a plan to ship in future Visual Studio tooling releases, you'll be able to just select WSL2 (Linux) as a compilation and debug target!


This will be Linux Deugging with SSH and WSL similar to VS Code Remote Development? I just want to be clear. In my development the next step beyond WSL is a Linux server. Would be nice to be able to deploy to my staging Linux server and debug and troubleshoot before going to production. It is a pain having to dump Visual Studio and use VS Code to debug and troubleshoot remote servers. Workflow WSL -> Linux staging -> Linux production all while using Visual Studio.

I'm hoping the extentions is for SSH and will help the MS ❤ Linux and not the Embrace Extend Extingiush. MS can't start to make things work only with WSL and at the same time say they love Linux. It will turn into MS ❤ WSL. My workflow is a mix between Visual Studio and VS code. It hurts my brain sometimes. I know the intentions with WSL/DirectX, but that is already backfiring. I could care less what MS does, but others do, I'm just giving a heads up. Don't drop your love for Linux.
Guy
May 29, 2020 14:39
There's something I can't stop thinking about. I have a very powerfull machine, but I end compiling my app in a container. In fact, multiple containers chained. Maybe for a CI/CD pipeline its better, but for local development?
May 30, 2020 18:51
I am really interested in why you are moving to docker vs using Azure App Service? I have been looking at docker but for anything that is easily hosted on Azure App Service I can’t see the benefit for the additional complexity it adds. Would love to hear your thoughts on when it makes sense to use CAAS rather than PAAS.
June 01, 2020 12:59
Nice, but seems that WSL2 is not quite there yet. It is almost unusable in daily life projects https://github.com/microsoft/WSL/issues/4166 .

Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.