Developing on Docker with the new and improved Visual Studio Container Tools (and WSL2)
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
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.
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.
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!
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.
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!
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!
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.
...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.
Comments are closed.