Varying-Vagrant-Vagrants / VVV

An open source Vagrant configuration for developing with WordPress
https://varyingvagrantvagrants.org
MIT License
4.54k stars 847 forks source link

Support for Docker with WSL2 on Windows #2444

Open davidshq opened 3 years ago

davidshq commented 3 years ago

VVV supports using Hyper-V as the provider which is great, but Hyper-V can be a bit heavy. Microsoft's Windows Subsystem for Linux 2 (WSL2) provides a lighter alternative. The latest versions of Docker utilize this alternative.

I'm wondering if it is currently possible or if support could be added for using Docker (which under the hood is using WSL2) on Windows as the provider for VVV?

Here is my current setup:

  1. Windows 10 Pro Build 19042
  2. Windows Subsystem for Linux 2 installed
  3. Docker installed (Desktop 3.3.1, Engine 20.10.5)
  4. Installed the Docker provider: vagrant plugin install docker
  5. Running vagrant up

Things start off okay but pretty early I get:

"The box you're attempting to add doesn't support the provider you requested. Please find an alternate box or use an alternate provider. Double-check your requested provider to verify you didn't simply misspell it."

Which makes sense, a virtualbox image is not the same as a docker image. I'm thinking I'll need to swap out the virtualbox image for a docker image...but I believe there are actually several images utilized in the creation of VVV VM's and so I'd actually need to replace each of these...

That is as far as I've gotten. Wondering if anyone else has made progress on this or if there is a roadmap for this feature, etc.?

tomjn commented 3 years ago

but Hyper-V can be a bit heavy

This issue is arguing that hyper-V is heavy therefore we should rely on another technology, but all the proposed tools are built using the very same hypervisor.

On Windows Docker uses Hyper-V to run a virtual machine containing Alpine Linux to act as a container host. A similar method is used with the Apple hypervisor on MacOS.

WSL2 uses virtualisation, specifically the Microsoft Virtualisation Platform feature that underpins Hyper-V.

Vagrant has a built in docker provider but it spins up a Virtualbox host VM. I could not find the docker plugin.

I would expect the performance of what you've suggested to be worse, not better, than just using Hyper-V directly, and that perhaps Hyper-V is not to blame for your performance woes.

tomjn commented 3 years ago

https://github.com/linuxkit/linuxkit and https://mobyproject.org/ in particular for Windows Docker VMs. For Windows containers there are other options, some of which involve no virtualisation, but as VVV is a Linux based project those don't apply here

tomjn commented 3 years ago

As for native or container based VVV, there's a #docker channel in the VVV slack

davidshq commented 3 years ago

Interesting, thanks for the additional resources. I also found Docker in Practice 2nd ed has a chapter that covers converting a VM image to a Docker image: https://livebook.manning.com/book/docker-in-practice-second-edition/chapter-3/1

Though it does recommend building from the ground-up as a better way to go.

I'm not too passionate about WSL2 being lighter than Hyper-V, so I won't raise any objection. I would note that Docker is planning on dropping Hyper-V VM's in favor of using WSL2.

thanks!

Chapter 3. Using Docker as a lightweight virtual machine · Docker in Practice, Second Edition
Converting a virtual machine to a Docker image · Managing the startup of your container’s services · Saving your work as you go · Managing Docker images on your machine · Sharing images on the Docker Hub · Playing—and winning—at 2048 with Docker
tomjn commented 3 years ago

That would be helpful in the long run if they did that. I've tried building images using our own provisioners in the past, they're linked in slack, there are others working on these things there.

Some further digging indicates WSL 2 uses App-V which isn't the same as Hyper-V, but I'm told that if WSL is active you'll want to be sure your system has plenty of ram or things will get sluggish

evertiro commented 3 years ago

Did I not have a Docker issue opened yet? It's been on my todo list since day one.