Quantcast
Channel: Scott Hanselman's Blog
Viewing all articles
Browse latest Browse all 1148

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

$
0
0

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!



© 2020 Scott Hanselman. All rights reserved.
     

Viewing all articles
Browse latest Browse all 1148

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>