wsl2 docker
I've written about WSL2 and it's glorious wonders many times. As its release (presumably) grows closer - as of this writing it's on Windows Insiders Slow and Fast - I wanted to update a few posts. I've blogged about a few cool thing around WSL and Docker
我已经写过有关WSL2的文章,这是许多光荣的奇迹。 随着它的发布(可能)越来越近-撰写本文时,它在Windows Insiders Slow和Fast中-我想更新一些帖子。 我已经写了关于WSL和Docker的一些很棒的文章
Docker Desktop for WSL 2 integrates Windows 10 and Linux even closer
适用于WSL 2的Docker桌面更紧密地集成了Windows 10和Linux
Remote Debugging a .NET Core Linux app in WSL2 from Visual Studio on Windows
从Windows上的Visual Studio远程调试WSL2中的.NET Core Linux应用
Cool WSL (Windows Subsystem for Linux) tips and tricks you (or I) didn't know were possible
您(或我)不知道的Cool WSL(Linux的Windows子系统)提示和技巧
Ruby on Rails on Windows is not just possible, it's fabulous using WSL2 and VS Code
Windows上的Ruby on Rails不仅可行,而且使用WSL2和VS Code很棒
Easily move WSL distributions between Windows 10 machines with import and export!
通过导入和导出轻松在Windows 10计算机之间移动WSL发行版!
What's the difference between a console, a terminal, and a shell?
控制台,终端和外壳之间有什么区别?
Here's a little HanselFAQ and some resources.
这里有一些HanselFAQ和一些资源。
You can certainly use HyperV or VirtualBox and run a standard Virtual Machine. Download an ISO and mount it and run "a square within a square." It won't be seamlessly integrated within Windows - it'll be like the movie Inception - but it's time-tested.
您当然可以使用HyperV或VirtualBox并运行标准虚拟机。 下载并安装ISO并运行“一个正方形内的一个正方形”。 它不会无缝集成到Windows中-就像电影Inception一样-但它已经过时间测试。
Better yet, install WSL or WSL2. It'll take 5-10 minutes tops if your Windows 10 is somewhat up to date.
更好的是,安装WSL或WSL2。 如果您的Windows 10是最新版本,则需要5到10分钟的停留时间。
How to install WSL on Windows 10
如何在Windows 10上安装WSL
How to install WSL on Windows 10
如何在Windows 10上安装WSL
How to install WSL2 on Windows 10
如何在Windows 10上安装WSL2
WSL2 ships an actual Linux kernel and its Linux file system is 5x-10x faster than WSL. WSL2 uses a tiny utility VM that expands contracts its memory and you can manage distros with the wsl command line.
WSL2附带了实际Linux内核,其Linux文件系统比WSL快5到10倍。 WSL2使用了一个微型实用程序VM,该VM扩展了其内存的收缩,您可以使用wsl命令行管理发行版。
Do all your development work inside here, while still using VS Code on Windows. It's amazing. Watch me set up a friend with WSL2, LIVE on YouTube.
在Windows上仍使用VS Code的同时,在这里进行所有开发工作。 太神奇了。 看着我在YouTube上与WSL2, LIVE结交朋友。
How to install WSL2 on Windows 10
如何在Windows 10上安装WSL2
There's 15 years of websites telling you to install Putty but you might not need it. OpenSSH has been shipping in Windows 10 for over two years. You can add them with Windows Features, or if you like, grab a release and put it on your PATH.
有15年的网站告诉您安装Putty,但您可能不需要它。 OpenSSH已在Windows 10中交付超过两年。 您可以使用Windows功能添加它们,也可以根据需要获取一个版本并将其放在PATH中。
You can also do things like set up keys to use Windows 10's built-in OpenSSH to automatically SSH into a remote Linux machine. I also like to setup Signed Git Commits with a YubiKey NEO and GPG and Keybase on Windows.
您还可以执行一些操作,例如设置密钥以使用Windows 10的内置OpenSSH自动将SSH连接到远程Linux计算机。 我还喜欢在Windows上使用YubiKey NEO和GPG和Keybase设置Signed Git Commit 。
The new Windows Terminal is for you. Download Windows Terminal now for free. It's open source. You can then run the Win64/Win32 ssh from above, or run any Linux distros SSH. Have fun. It's time.
新的Windows终端适合您。 立即免费下载Windows Terminal 。 它是开源的。 然后,您可以从上面运行Win64 / Win32 ssh,或者运行任何Linux发行版SSH。 玩得开心。 时间到了
NOTE: Have you already downloaded the Terminal, maybe a while back? Enough has changed that you should delete your profiles.json and start over.
注意:您是否已经下载了终端,也许是在不久前? 足够的更改,您应该删除profiles.json并重新开始。
You can download the Windows Terminal from the Microsoft Store or from the GitHub releases page. There's also an unofficial Chocolatey release. I recommend the Store version if possible.
您可以从Microsoft Store或GitHub版本页面下载Windows终端。 还有一个非官方的Chocolatey版本。 如果可能,我建议使用商店版本。
Make them pretty. You deserve the best. Go get Cascadia Code's CascadiaPL.ttf and PowerLine and buckle up buttercup. Get a nice theme and maybe a GIF background.
使它们漂亮。 您应该得到最好的。 去获取Cascadia Code的CascadiaPL.ttf和PowerLine并扣上毛butter。 获得一个不错的主题,也许还有一个GIF背景。
Surprise, it's actually awesome. You may have had some challenges with Docker a few years ago on Windows and gave up, but come back. There's been a huge (and fascinating) architecture of Docker on Windows. It's very nicely integrated if you have WSL2.
惊喜,它实际上很棒。 几年前,您可能在Windows上使用Docker遇到了一些挑战,并放弃了,但是回来了。 Windows上有一个庞大(且引人入胜)的Docker架构。 如果您有WSL2,它将很好地集成在一起。
If you have WSL2 set up nicely, then get Docker Desktop WSL2. This version of Docker for Windows uses WSL2 as its engine allowing you to share your docker context across Windows and Linux on the same machine! As the maker intended!
如果您对WSL2的设置很好,请获取Docker Desktop WSL2。 此版本的Windows版Docker使用WSL2作为其引擎,使您可以在同一台计算机上的Windows和Linux上共享Docker上下文! 作为制造商的意图!
WSL 2 introduces a significant architectural change as it is a full Linux kernel built by Microsoft, allowing Linux containers to run natively without emulation. With Docker Desktop running on WSL 2, users can leverage Linux workspaces and avoid having to maintain both Linux and Windows build scripts.
WSL 2引入了重大的体系结构更改,因为它是Microsoft构建的完整Linux内核,允许Linux容器在没有仿真的情况下本机运行。 通过在WSL 2上运行的Docker Desktop,用户可以利用Linux工作区,而不必维护Linux和Windows构建脚本。
So that means
所以这意味着
Enable WSL 2 feature on Windows. For detailed instructions, refer to the Microsoft documentation.
在Windows上启用WSL 2功能。 有关详细说明,请参阅Microsoft文档。
Download Docker Desktop Edge 2.1.6.0 or a later release.
下载Docker Desktop Edge 2.1.6.0或更高版本。
Ensure your default WSL instances is WSL2. You can do that with wsl -l -v
, and then wsl --set-version
确保默认的WSL实例为WSL2。 您可以使用wsl -l -v
,然后使用wsl --set-version
Then within Docker Desktop for Windows you've got two things to check. First, are you using WSL2 as your backend?
然后,在Windows版Docker Desktop中,您需要检查两件事。 首先,您是否使用WSL2作为后端?
And then, the often missed setup, check under Resources | WSL Integration and tell Docker which WSL2 distros you want to use to access Docker. If you're paying attention you may notice that Docker Desktop tries to prompt you with a notification in Action Center but you might miss it.
然后,经常错过的设置,请在参考资料|网站上进行。 WSL集成,并告诉Docker您要使用哪个WSL2发行版来访问Docker。 如果您正在关注,您可能会注意到Docker Desktop试图在Action Center中用提示来提示您,但您可能会错过它。
NOTE: If you used an early Tech Preview, you might have an extra now-vestigial Docker context named "wsl." You want to use the Default one, not the WSL one.
注意:如果您使用了早期的Tech Preview,则可能会有一个额外的现在正在研究的Docker上下文,名为“ wsl”。 您要使用默认值之一,而不要使用WSL。
This isn't intuitive or obvious and you might get weird errors like these
这不是直观的或显而易见的,您可能会遇到类似以下的奇怪错误
docker wsl open //./pipe/docker_wsl: The system cannot find the file specified.
or
要么
error during connect: Get http://%2F%2F.%2Fpipe%2Fdocker_wsl/v1.40/images/json?all=1: open //./pipe/docker_wsl: The system cannot find the file specified.
You can see if you have an extra context from before like below. That "wsl" one is older (if you have it) and you want to use default in both Windows and WSL2.
您可以像以前一样查看是否有其他上下文。 该“ wsl”是旧的(如果有的话),并且您想在Windows和WSL2中都使用default。
docker context ls
NAME DESCRIPTION DOCKER ENDPOINT KUBERNETES ENDPOINT
default * Current DOCKER_HOST based configuration npipe:./pipe/docker_engine https://kubernetes.docker
wsl Docker daemon hosted in WSL 2 npipe:./pipe/docker_wsl
I actually removed that one to avoid confusion with docker context rm wsl
.
我实际上删除了那个以避免与docker context rm wsl
混淆。
Here's Ubuntu on my Windows machine
这是Windows计算机上的Ubuntu
And here's my Windows machine. Note that docker images in both instances returns the same list. They are the same Docker backend!
这是我的Windows计算机。 请注意,这两个实例中的docker映像将返回相同的列表。 它们是相同的Docker后端!
At this point once I've set things up I can go bananas. I can do Container-based development, where I use VS Code to run all my developer tools and builds insider a container...maybe I never event install Go or PHP or .NET Core. It's all just inside a container.
现在,一旦我设置好东西,我就可以去吃香蕉了。 我可以进行基于容器的开发,在其中我可以使用VS Code运行我所有的开发人员工具并在容器内部构建……也许我从来没有安装Go或PHP或.NET Core。 都在一个容器里。
Oh, by the way, please Subscribe to my YouTube! I talk a lot about this stuff over there.
哦,顺便说一句,请订阅我的YouTube ! 我在那边谈论了很多东西。
翻译自: https://www.hanselman.com/blog/how-to-set-up-docker-within-windows-system-for-linux-wsl2-on-windows-10
wsl2 docker