How to create an environment that uses Docker (WSL2) and Vagrant (VirtualBox) together on Windows

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/

Premise

1. WSL2 + Ubuntu 2004 installation

Until the first reboot

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. ** **

Until the second reboot

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 settings

** 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.

2. Install VirtualBox + Vagrant

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.

3. Docker Desktop installation

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.

Supplement

Other distributors

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

Harmful effects on the VirtualBox side

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. .. ..

reference

Record of previous challenges

Notes on installing all WSL2 with commands https://qiita.com/mainy/items/19862ebb1fa4df2ad497

Recommended Posts

How to create an environment that uses Docker (WSL2) and Vagrant (VirtualBox) together on Windows
Organize communication in an environment that uses various resources on the host machine and Docker container
Let's install Docker on Windows 10 and create a verification environment for CentOS 8!
[Docker] How to create a virtual environment for Rails and Nuxt.js apps
Rails6.0 ~ How to create an eco-friendly development environment
[Rails] How to build an environment with Docker
[First environment construction] I tried to create a Rails 6 + MySQL 8.0 + Docker environment on Windows 10.
[Even beginners can do it! ] How to create Java environment on Windows 10 (JDK14.0.1)
How to start with Hyper-V instead of WSL2 on Docker Desktop for Windows
How to share on the host side (windows) and guest side (CentOS 7) with VirtualBox
I built an Ubuntu environment on Windows 10 using WSL2.
I installed CentOS 8 on Windows 10 using VirtualBox and Vagrant
(Ruby on Rails6) How to create models and tables
Create Chisel development environment with Windows10 + WSL2 + VScode + Docker
How to quit Docker for Mac and build a Docker development environment with Ubuntu + Vagrant
Create an environment where CircleCI can be executed locally with Windows10 + WSL2 (Ubuntu) + Docker
How to create an application
How to create an application server on an EC2 instance on AWS
I tried to create React.js × TypeScript × Material-UI on docker environment
How to make an application with ruby on rails (assuming that the environment has been built)
Response to WSL2 docker throwing an error after updating Docker for Windows
Until you put Ubuntu 20 on Windows 10 Home and WSL2 and run Docker
How to create a web server on an EC2 instance on AWS
[Java] How to update Java on Windows
How to run JavaFX on Docker
Using Docker on Windows10 Home WSL2
Challenge to install WSL2 and docker
[Win10 Home Docker environment memo (WSL2 or vagrant)] How to deal with the problem that the loading time of localhost is abnormally long
Build a web application development environment that uses Java, MySQL, and Redis with Docker CE for Windows
How to quickly create a reverse proxy that supports HTTPS with Docker
How to build a Ruby on Rails environment using Docker (for Docker beginners)
How to build a Ruby on Rails development environment with Docker (Rails 6.x)
[Node.js express Docker] How to define Docker environment variables and load them with node.js
How to build a Ruby on Rails development environment with Docker (Rails 5.x)
I tried migrating the portfolio created on Vagrant to the Docker development environment
How to create a convenient method that utilizes generics and functional interfaces
Windows Docker: Disk pressure on WSL files
Create Spring Boot development environment on Vagrant
I installed WSL2 without using Microsoft Store and tried to build an environment where Docker can be used
How to use OrientJS and OrientDB together
[Docker] Building an environment to use Hugo
How to publish an application on Heroku
Introducing Docker Desktop for Windows on WSL2
Build an environment with Docker on AWS
Build an Ultra96v2 development environment on Docker 1
Note: [Docker] How to start and stop
How to use @Builder and @NoArgsConstructor together
Install Docker and create Java runtime environment
How to build Rails 6 environment with Docker
Building an environment for WordPress, MySQL and phpMyAdmin with Docker Compose on EC2
How to mount the batch file location via WSL2 and start the Docker container
Create an ARM-cpu environment with qemu on mac and run java [Result → Failure]
How to build an environment of [TypeScript + Vue + Express + MySQL] with Docker ~ Vue edition ~
Build a development environment to create Ruby on Jets + React apps with Docker
How to build a Jenkins server with a Docker container on CentOS 7 of VirtualBox and access the Jenkins server from a local PC
How to make rbenv recognize OpenSSL on WSL
How to create a class that inherits class information
Docker on Ubuntu18.04 on WSL2 and VSCode installation instructions
Let's quickly create an app that uses Firestore! !!
Create an Annotator that uses kuromoji with NLP4J [007]
Operate Docker Desktop for Windows on Linux (WSL)