I wanted to use Vagrant and Docker together on Windows 10, but it didn't work well and I gave up every time. But finally. .. .. I finally got it. .. ..
Since it is possible to build with only commands, I think that it can be built easily without mistakes.
(Addition) It seems that VirtualBox 6.1.16 or later can be used stably with WSL 2. http://kzlog.picoaccel.com/virtualbox-coexist-with-wsl2-hyper-v/
Enables Windows features. ** Start PowerShell with administrator privileges ** and enter the following command.
PowerShell (administrator privileges)
#Windows subsystem for Linux
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
#Windows hypervisor platform
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
#Virtual machine platform
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
** Now restart your computer. ** **
Make WSL2 available and install Ubuntu. Start PowerShell (with normal privileges) and enter the following command:
The distribution is Ubuntu 2004, but if other distributions are good, please refer to the supplement.
PowerShell
# WSL 2 Kernel Update
Invoke-WebRequest -Uri https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi -OutFile wsl_update_x64.msi -UseBasicParsing
msiexec /i wsl_update_x64.msi /passive /norestart
rm wsl_update_x64.msi
#Standardize WSL 2
wsl --set-default-version 2
#Install Ubuntu 2004
Invoke-WebRequest -Uri https://aka.ms/wslubuntu2004 -OutFile linux.appx -UseBasicParsing
Add-AppxPackage -Path linux.appx
rm linux.appx
** Now restart your computer. ** **
** Ubuntu 20.04 LTS ** has been added to the start menu, so run it. The initial settings will be performed the first time, so
--UNIX user name --UNIX password
Set and you're done.
WSL2 + Ubuntu is now available. Close Ubuntu.
Scoop
With Scoop installed, you can install applications with commands.
Click here for the official page https://scoop.sh
Start Power (with normal privileges) and enter the following command.
PowerShell
#If you don't have PowerShell execution policy permission, execute this as well
Set-ExecutionPolicy RemoteSigned -scope CurrentUser
#Scoop installation
iwr -useb get.scoop.sh | iex
#Git installation (required because it is used to manage Scoop. Not required if you have Git installed separately)
scoop install git
#Add Bucket to install more apps
scoop bucket add extras
scoop bucket add nonportable
#sudo installation (because you don't have to start PowerShell with administrator privileges in the future)
scoop install sudo
You can now install the famous app with a command.
Close PowerShell.
VirtualBox + VirtualBox Extension Pack + Vagrant
With Scoop, setup is complete in just two lines! Start PowerShell (with normal privileges) and enter the following command:
PowerShell
# VirtualBox &VirtualBox Extension Pack installation
scoop install virtualbox-with-extension-pack-np
#Vagrant installation
scoop install vagrant
You can now use the complete Vagrant set. Close PowerShell.
If you install it normally, many people will be stuck due to the omission of the VirtualBox Extension Pack installation, so you can prevent such sad mistakes.
If you install Docker with Scoop, the previous version of Docker Toolbox will be installed. WSL2 is supported by Docker Desktop, so we will use Chocolatey to install it.
Chocolatey
Chocolatey can also install applications with commands. However, it is not as easy to use as Scoop, so this is used to install apps that are difficult to install with Scoop.
Chocolatey https://chocolatey.org/
** Start PowerShell with administrator privileges ** and enter the following command.
PowerShell (administrator privileges)
#Chocolatey installation
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
Close PowerShell.
Docker Desktop
Start PowerShell (with normal privileges) and enter the following command:
PowerShell
#Docker Desktop installation
sudo choco install -y docker-desktop
Installing with Chocolatey requires administrator privileges, so you need to be careful about how to start PowerShell during installation. However, since I installed sudo with Scoop earlier, I think I could easily elevate it to administrator privileges on a command-by-command basis.
You can now use Docker. Close PowerShell.
At this point, you should have an environment where you can use Docker (WSL2) and Vagrant (VirtualBox) together on Windows.
The above installs Ubuntu 2004, but other distributions can also be installed with the command.
Change the URI passed to the argument -Uri
.
Check the link at https://docs.microsoft.com/en-us/windows/wsl/install-manual#downloading-distros for the URI.
For example, if you want to use Debian GNU/Linux, it looks like the following.
PowerShell
# Debian GNU/Linux
Invoke-WebRequest -Uri https://aka.ms/wsl-debian-gnulinux -OutFile linux.appx -UseBasicParsing
Add-AppxPackage -Path linux.appx
rm linux.appx
It seems that some compatibility with the guest OS is bad. I tried using Windows 10 as the guest OS, but it still didn't work. Ubuntu 2004 ⁺ GUI is working fine. .. ..
Record of previous challenges
Notes on installing all WSL2 with commands https://qiita.com/mainy/items/19862ebb1fa4df2ad497