I tried to build the environment of WSL2 + Docker + VSCode

What kind of article

I will leave the details of WSL2 etc. to other people, but for the time being I tried to summarize the things that got stuck in the installation etc.

I was in trouble without checking the procedure properly, so I will write some things that I was in trouble after the official procedure. (Everyone is encouraged to read the documentation properly)

The details will be in English Docs, but I think you should take a look at the official version. If you are interested in reference materials, please check only the items in the reference materials at the bottom.

Prerequisites

You need to check the build version of Windows.

Open Run from Command in windows + R and enter the following command.

winver

It will be displayed as follows.

image.png

Make sure the value for this version is 1903 or higher. (This number will be relevant later.)

Preparing for WSL2

I have prepared an English link below, but please do not translate it into Japanese. Because, at present (as of September 23, 2020), the English document has been updated first, so the content is slightly different from the Japanese one. Maybe there was a recent update and I haven't updated it in Japanese yet (the English version was updated on 9/15/2020).

https://docs.microsoft.com/en-us/windows/wsl/install-win10

Open Power Shell with administrator privileges and execute the following command. The following command enables WSL.

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

(Maybe you need to reboot here first) Then enable the "Virtual Machine Platform" optional feature.

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

Now restart your PC.

Drop the msi file from the link below and run it to update the Linux kernel. (If this is Japanese docs, it wasn't new yet, so I got stuck)

https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi

Finally, set the default version of WSL to WSL2.

wsl --set-default-version 2

The WSL that will be added later may be WSL2.

Ubuntu preparation

Put Ubuntu in the Microsoft Store. image.png

I think you can choose from the three on the left. I'm using Ubuntu-20.04 here. There is no particular reason.

VS Code preparation

Let's install the extension.

image.png

Right-click on the desired linux (downloaded from the Microsoft Store) and select "connect WSL". image.png

It looks like something went wrong. image.png

After that, the operation on the WSL side was done from here.

Docker preparation

We will proceed according to the following. https://docs.docker.com/docker-for-windows/wsl/

Run the winver command as you did at the beginning to install the Docker Desktop for each version. --1903 and above: Edge version --2004 and above: Stable version

Download site https://hub.docker.com/editions/community/docker-ce-desktop-windows/

Go to the General page from Settings.

image.png

Check Use WSL 2 based engine and Apply & Restart.

Make settings such as WSL integration. Apply & Restart by turning on the following items from the Docker Desktop settings. image.png

When I connected with VSCode, I was able to hit the docker command safely! image.png

Clogged points

The errors that I caused as a result of not completely following the official order by touching it a little before (laugh)

wsl command does not pass

In the first place, there were times when the wsl command did not pass. Especially when fixing it, I didn't mess with the environment variable path. When I restarted it or re-entered the command, the command passed. So maybe I just missed some steps.

WSL version

It was wsl (1) and I couldn't type the docker command. (Because I missed the procedure) If you open Powershell with administrator privileges on the original machine and type the following command

wsl -l -v

I knew the version like this. image.png

If the target WSL is ver1, use the following command to raise ver.

wsl --set-version Ubuntu-20.04 2

The above command sets Ubuntu-20.04 to WSL2 (see image above).

Points to check when jammed

After all, it is difficult (for me who does not read properly) to do it in order. I wrote a little about what happened when that happened.

Find out where the error (?) Originated

This time, the elements VSCode, Docker Desktop, and WSL2 are involved. So, when an error occurred, it was important to check from which one. You're probably getting some kind of error, so don't panic and check the error message. (Specifically, this time it led to checking from the error message that the version of wsl is different, etc.)

Believe in the official documentation (in English as much as possible)

After all, I felt that there were many mistakes in my procedure in the pattern where an error occurred by referring to the formula related to such construction. So, I felt that it was somehow effective to check from the error message to see if something was missing, or to start over from the beginning of the procedure.

If there is still no information, I felt that it would be better to search the Web with a separate error message.

Reference material

Recommended Posts

I tried to build the environment of WSL2 + Docker + VSCode
I tried to build the environment of PlantUML Server with Docker
I tried to summarize the state transition of docker
I tried to build an environment using Docker (beginner)
I tried to build a laravel operating environment while remembering Docker
I tried to build a Firebase application development environment with Docker in 2020
I tried migrating the portfolio created on Vagrant to the Docker development environment
WSL2 + VSCode + Docker development environment
I tried the Docker tutorial!
Build docker environment with WSL
05. I tried to stub the source of Spring Boot
I tried to reduce the capacity of Spring Boot
[WIP] I tried the configuration of Docker + Streama + NFS
When I tried to build an environment of PHP7.4 + Apache + MySQL with Docker, I got stuck [Windows & Mac]
I installed WSL2 without using Microsoft Store and tried to build an environment where Docker can be used
I tried to summarize the basics of kotlin and java
Build PlantUML environment with VSCode + Docker
[Swift] I tried to implement the function of the vending machine
I tried to explain the method
I tried to summarize the basic grammar of Ruby briefly
I was addicted to the setting of laradock + VSCode + xdebug
I tried to create React.js × TypeScript × Material-UI on docker environment
I want to narrow down the display of docker ps
I tried to create a padrino development environment with Docker
[Rails 6.0, Docker] I tried to summarize the Docker environment construction and commands necessary to create a portfolio
I tried to develop the cache function of Application Container Cloud Service in the local environment
I tried to solve the problem of "multi-stage selection" with Ruby
Build Go development environment with WSL2 + Docker Desktop + VSCode (Remote --Containers)
I tried to build an http2 development environment with Eclipse + Tomcat
I tried to check the operation of gRPC server with grpcurl
I tried to summarize the methods of Java String and StringBuilder
I examined the concept of the process to understand how Docker works
I tried to solve the problem of Google Tech Dev Guide
I tried to summarize the methods used
I tried to summarize the Stream API
I tried to build AdoptOpenjdk 11 on CentOS 7
What is Docker? I tried to summarize
I tried to build Ruby 3.0.0 from source
How to build Rails 6 environment with Docker
I tried using Docker because I don't want to pollute the local environment in Microsoft Teams tab development of MS Learn
What I was addicted to when updating the PHP version of the development environment (Docker) from 7.2.11 to 7.4.x
I tried to take a look at the flow of Android development environment construction with Android Studio
Problems I was addicted to when building the digdag environment with docker
I tried to summarize the key points of gRPC design and development
01. I tried to build an environment with SpringBoot + IntelliJ + MySQL (MyBatis) (Windows10)
I tried to make full use of the CPU core in Ruby
I tried to visualize the access of Lambda → Athena with AWS X-Ray
I had to lower the PHP version in Docker + Composer + Laravel environment
I tried to measure and compare the speed of GraalVM with JMH
After all I wanted to preview the contents of mysql with Docker ...
I tried using Docker for the first time
I want to output the day of the week
I tried to organize the session in Rails
Build a Laravel / Docker environment with VSCode devcontainer
Improve the performance of your Docker development environment
I tried to chew C # (basic of encapsulation)
I want to var_dump the contents of the intent
I tried to build AdoptOpenJDK 8 (Addition: Amazon Corretto 8)
I tried touching Docker for the first time
I tried to set tomcat to run the Servlet.
I tried to build Micra mackerel in 1 hour!