wsl 上使用docker_使用新的和改进的Visual Studio容器工具(和WSL2)在Docker上进行开发

wsl 上使用docker

wsl 上使用docker

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.

最近,我在Docker上花了很多时间。 Windows上的Docker桌面很棒,而且每天都在变得越来越好。 既然WSL2(适用于Linux的Windows子系统)将在未来几周内稳定推出,并且Docker桌面支持WSL直接托管Linux容器,我发现自己使用Visual Studio在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!

Visual Studio容器工具也在积极改进,最新版本非常不错。 您可能已经拥有此功能,因为从版本16.4 Preview 2及更高版本开始, Visual Studio 2019中已包含容器工具窗口!

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

注意:请确保还签出Visual Studio Code Docker扩展

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.

令人印象深刻的第一件事是Visual Studio现在试图在有用的指导下帮助您成功到达某个地方,因为有时设置可能会令人望而生畏。

When you create or open a Docker-enabled project:

创建或打开支持Docker的项目时:

  • VS container tools help you install Docker Desktop

    VS容器工具可帮助您安装Docker Desktop
  • VS container tools make sure Docker Desktop is running

    VS容器工具确保Docker Desktop正在运行
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!

如果您已在Visual Studio 2019中安装了Web或Azure工作负载,则您已经拥有容器工具,并且它包含在免费的Visual Studio 2019社区中

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

您可以在创建项目时使用复选框对Docker启用Docker,也可以在事实之后右键单击Add Docker Support。

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.

当使用.NET Core时,容器工具将构成一个很好的多阶段Dockerfile,其中封装了最佳实践。 它使用Docker分层在使用.NET SDK的Docker中进行构建,然后将其发布到较小的运行时容器中,以生成尽可能最小的图像,从而获得最大的密度。

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!

过去,使用多个容器调试实际系统一直是一个挑战。 VS2019现在内置了Container Orchestrator支持。 此屏幕快照显示Docker Compose在标准VS2019工具栏中显示为调试目标!

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.

一旦有一堆容器在运行,容器工具将在显示文本日志和摆脱干扰之间找到一个不错的平衡,同时还为您提供GUI来启动,停止和管理多个正在运行的容器。

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.

您可以在下面的图像中看到解决方案容器。 我什至可以在运行Linux容器中右键单击并附加到进程! 再次,所有使用WSL2和邪恶的快速。

Docker Container Tools

即将推出Visual Studio! WSL2本机调试 (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.

我喜欢我的容器,但如果您只想直接在Linux上进行开发(不使用容器),那么这是您将最兴奋的“即将推出”-WSL 2调试! 即将作为预览版进入市场,并计划在将来的Visual Studio工具版本中发布,您只需选择WSL2(Linux)作为编译和调试目标! 这意味着可以直接从VS在Windows上进行开发/测试/运行本机Linux。

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使用了真正Linux内核,因此这里没有模拟器。 WSL2 Linux将在大约一秒钟内启动,您将调试FAST。 WSL2正在推出

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!

这意味着从Windows上的Visual Studio 2019在Linux上进行断点和全面调试。 我和斯科特·亨特(Scott Hunter)谈到了这一点,并在今年的BUILD上的“一个网之旅”演讲中演示了一个演示,您可以在这里免费观看

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

如果您想要所有这些不错的容器工具,请安装VS2019或仅运行Visual Studio安装程序并更新现有安装。

翻译自: https://www.hanselman.com/blog/developing-on-docker-with-the-new-and-improved-visual-studio-container-tools-and-wsl2

wsl 上使用docker

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值