Explode Docker with WSL2

My Win10 has finally enabled WSL2 on the last Windows Update.

Let's make Docker compatible with WSL2 immediately according to the official procedure https://docs.docker.com/docker-for-windows/wsl/

Before that, What's WSL2

WSL is an abbreviation for Windows Subsystem For Linux You can think of it as something that allows you to use Linux commands on the Windows command line.

WSL2 is version 2 of WSL. However, it is not fully upward compatible with WSL1 and has advantages and disadvantages. https://docs.microsoft.com/ja-jp/windows/wsl/compare-versions

First, check the assumptions

  1. Docker, version 2.3.0.2 or higher
  2. Windows10, version 2004, build 19041 and above

Install WSL2

First, get Ubuntu from the Microsoft Store

The Linux OS used for WSL is Ubuntu for versatility. The file size is large, but I think it is the most recommended for WSL. https://www.microsoft.com/ja-jp/p/ubuntu/9nblggh4msv6?activetab=pivot:overviewtab

Update to WSL2

If it is left as it is, it will be installed by WSL1, so let's update to WSL2.

#Check installed WSL and version
wsl -l -v
  NAME                   STATE           VERSION
* Ubuntu                 Running         1

The default WSL is marked with *. If you have multiple Linux in WSL, you will get a lot. Normally, the default WSL is integrated with Docker.

#Upgraded WSL
wsl --set-version Ubuntu 2

#Double-check the installed WSL and version
wsl -l -v
  NAME                   STATE           VERSION
* Ubuntu                 Running         2

If the Ubuntu version is 2, you are successful.

Enable WSL2 on Docker For Windows now

  1. Go to Settings> General and check ʻUse WSL 2 based engine ʻApply & Restart image.png

  2. Settings> Resources> WSL Integration The integration function is enabled in the default WSL. image.png

Now, Docker, which used to run on virtual machines on Hyper-V, now runs on WSL2.

But the pitfalls

Although WSL2 is now fully Linux, it has the disadvantage of slowing performance with Windows file sharing. As a result, if I shared a local Windows folder to a container with volumes, it would feel quite slow.

Solved by placing the source code in the Linux file system

If you share the area under / mnt / c / which is the shared area of wsl with Windows with volumes, it will be slow, so Put your program code somewhere else. The official best practices also say so. https://docs.docker.com/docker-for-windows/wsl/#best-practices

VS Code Dev Container development with WSL2 Docker

https://docs.docker.com/docker-for-windows/wsl/#develop-with-docker-and-wsl-2

If you execute the code command in WSL, VS Code of Windows will open in Remote-WSL mode! !! !!

code ~/hoge_workspace/

After that, prepare devcontainer.json in the folder in WSL and follow the usual procedure Reopen in Container image.png image.png

DevContainer related

-Develop on Docker on remote host with VS Code -Building the fastest development environment using Haskell extension of VS Code

Access the WSL directory from Windows 10 Explorer

You can access the folders in WSL with Explorer by accessing the following network path while Linux in WSL is running. You can also edit the file from Windows as it is.

\\wsl$\

Recommended Posts

Explode Docker with WSL2
Docker autostart settings with wsl2
Build docker environment with WSL
Image flew when updating Docker with WSL2
GPU recognition with docker using WSL2 (August 2020)
Install Docker with WSL2 Memo ([Part 2] Docker introduction)
Comfortable development life with WSL2 + Docker Desktop + GPU
Launch MariaDB with Docker
Rails deploy with Docker
Run Pico with docker
Use Puphpeteer with Docker
Operate Emby with Docker
Try WildFly with Docker
Use ngrok with Docker
Run Payara with Docker
[Docker] Connection with MySQL
Php settings with Docker
Getting Started with Docker
Disposable PHP with Docker
Docker installation on WSL2
Install Composer with Docker
Feel free to try Elasticsearch cluster with WSL2 + Docker
Build Java development environment with WSL2 Docker VS Code
Comfortable Docker environment created with WSL2 CentOS7 and Docker Desktop
Create Chisel development environment with Windows10 + WSL2 + VScode + Docker
Pytorch execution environment with Docker
Use GDAL with Python with Docker
WSL2 + VSCode + Docker development environment
Deploy with EC2 / Docker / Laravel
Docker management with VS Code
Run Rails whenever with docker
Get started with DynamoDB with docker
[Docker] Rails 5.2 environment construction with docker
Spring Boot starting with Docker
Version control CocoaPods with Docker
Web application built with docker (1)
I tried BIND with Docker
React environment construction with Docker
Build DynamoDB local with Docker
[Docker] Use whenever with Docker + Rails
Using PlantUml with Honkit [Docker]
Measures for permissions when building MySQL with Docker on WSL2
Rails + MySQL environment construction with Docker
Create a Vue3 environment with Docker!
Node.js environment construction with Docker Compose
Run lambda with custom docker image
Build Go development environment with WSL2 + Docker Desktop + VSCode (Remote --Containers)
Install java with Ubuntu 16.04 based Docker
Build a Node.js environment with Docker
Environment construction with Docker for beginners
[PDO → DB connection with docker, PHP]
Run SQL Server with Docker ToolBox
Easily Docker Java applications with Jib
Why use orchestration tools with Docker
Build PlantUML environment with VSCode + Docker
Try running cloudera manager with docker
Molecular phylogenetics exercise with docker (working)
IP address interfered with Docker bridge
Build environment with vue.js + rails + docker
Read dump file with Docker MySQL
Hello World with Docker and C