WSL2 + VSCode + Docker development environment

Overview

Build a modern development environment using WSL2 (Windows Subsystem for Linux ver2), Visual Studio Code (hereinafter VSCode), and Docker Desktop, which can build a Linux environment on Windows.

Readers of this article

--Developers on Windows --People who are developing with Docker, people who want to go from now on --I don't do cmd. Use bash, people

Installing WSL2

WSL2 could only be installed on Windows 10 version 2004 (May 2020 Update) or later, but since 2020/8 it can also work on 1903/1908.

["WSL 2" is now available for "Windows 10 version 1903/1909" -Microsoft ported to older OS-Window Forest](https://forest.watch.impress.co.jp/docs/news/ 1272017.html)

The following are common tasks for 1903/1908/2004.

  1. Open the control panel.

    2020-09-11_09h44_50.png

  2. Open "Turn Windows features on or off".

    2020-09-11_09h46_10.png

  3. Check "Windows Subsystem for Linux" and press the OK button.

    2020-09-11_09h48_44.png

  4. You will need to reboot after the installation is complete.

This is a Linux-only environment setup that requires a CentOS or Ubuntu distribution.

Introducing Ubuntu

You can download it directly from the Windows Store.

If you start the Windows Store and search for Ubuntu, it will appear, so you won't get lost.

If you cannot use the Windows Store in a company environment, you can download it from the following site.

Please select Ubuntu.

https://docs.microsoft.com/ja-jp/windows/wsl/install-manual

You can install it by clicking the downloaded file.

When the installation is complete, the Ubuntu terminal will launch.

First, decide on your Linux username and wasword. Please put any one.

The shell will start and be ready for use. Leave the terminal as it is.

2020-09-11_10h10_09.png

Connect Visual Studio Code to WSL

If VSCode is not included, please enter it from the following.

https://azure.microsoft.com/ja-jp/products/visual-studio-code/

Start VSCode and search for wsl from the extension.

(In the image below, it is already installed)

2020-09-11_10h06_04.png

Once installed, close VSCode once.

Launch Visual Studio Code from Ubuntu

Select [Ubuntu] from the Windows Start menu to start the terminal.

Create an empty directory here and start VSCode there.

mkdir sample
cd sample
code .

VSCode will start. Launch a terminal (ctrl + @, ctrl + `for US keyboards) and make sure the shell is bash.

2020-09-30_14h57_36.png

If you want to open an existing git project from VSCode, you need to download it with the git clone command.

Also, as will be described later, Ubuntu files can also be referenced in Explorer, so

!Note!

From Ubuntu, you can also access Windows files by accessing / mnt / c /.

However, launching with VSCode's Remote feature under this will result in poor performance and the inability to monitor files, causing problems with behavior such as when files are added or modified.

If you want to use the Remote function of VSCode, create it under your home directory (accessible with cd ~).

Access from explorer

You can browse Ubuntu files by accessing \\ wsl $ \ Ubuntu \ from Explorer.

You can continue to use Tortoises git.

Docker Desktop WSL2 support

Docker Desktop now supports WSL2. However, 1903/1908 is supported with the intention of 2.3.6.0 in the Early Access version (Edge), and is not supported in the stable version (Stable). (As of 2020-09-30)

The advantage of running on WSL2 is improved performance, especially faster container construction and startup. In addition, the performance improvement can be felt even with the docker datamon startup when the PC is started and the remote function of VSCode.

Docker Desktop WSL 2 backend | Docker Documentation

For new installation

During the installation, you will be asked if you want to use WSL2 and press Yes.

If installed

From the [Docker] menu, select [Setting]> [General], and check [User the WSL2 base engine] there.

Click Apply & Restart to save and restart Docker Desktop.

wsl2-enable.png

Launch on WSL2

In the Ubuntu shell, run the command docker version to see the Docker information.

2020-09-30_15h57_25.png

You can launch VSCode on Ubuntu and from there you can launch Docker in Remote Containers and connect.

Finally

For system development, a shell such as Bash is convenient, and macOS is often used as the development environment. Docker Desktop also has poor performance on Windows.

By using WSL2, you can easily prepare a Linux environment in Windows, and the performance performance is higher than using Hyper-V etc. In addition, WSL allows you to switch the environment according to your development project.

Until now, if you've only used Windows, you'll need to learn Linux, but when you're involved in development, you'll often find yourself stuck in Linux. Isn't it okay to use this as a trigger for learning?

Recommended Posts

WSL2 + VSCode + Docker development environment
Create Chisel development environment with Windows10 + WSL2 + VScode + Docker
Build Go development environment with WSL2 + Docker Desktop + VSCode (Remote --Containers)
Build a development environment for Docker, java, vscode
Build docker environment with WSL
Build Java development environment with WSL2 Docker VS Code
Debug the VSCode + Docker + PHP development environment with XDebug.
Build PlantUML environment with VSCode + Docker
Build Unity development environment on docker
I tried to build the environment of WSL2 + Docker + VSCode
Laravel development environment construction with Docker (Mac)
Ruby on Rails development environment construction with Docker + VSCode (Remote Container)
Sapper × Go (echo) × Docker development environment construction
Build a PureScript development environment with Docker
Create Spring Boot-gradle-mysql development environment with Docker
Java development environment
[Docker] Development environment construction Rails6 / Ruby2.7 / MySQL8
Spring Boot + Docker Java development environment construction
Build a Wordpress development environment with Docker
Docker environment construction
Build an Ultra96v2 development environment on Docker 1
Lightweight PHP 7.4 development environment created with Docker
Build a simple Docker + Django development environment
Comfortable development life with WSL2 + Docker Desktop + GPU
Build a development environment for Docker + Rails6 + Postgresql
Build a Laravel / Docker environment with VSCode devcontainer
Prepare the JVM language development environment with WSL
Build a WordPress development environment quickly with Docker
Kaggle environment construction using official Docker and vscode
Improve the performance of your Docker development environment
Build a simple Docker Compose + Django development environment
WSL2 + transparent proxy improves Docker under proxy environment (slightly)
WSL, Zsh, VSCode, Docker, NodeJS setup summary in 2020
Docker on Ubuntu18.04 on WSL2 and VSCode installation instructions
Rails development environment created with VSCode and devcontainer
A reminder of Docker and development environment construction
Points stuck in building VSCode & Java development environment
[First team development ②] Build an environment with Docker
Wordpress local environment construction & development procedure with Docker
Create a Spring Boot development environment with docker
Java development environment memo
Rails Docker environment construction
Explode Docker with WSL2
java development environment construction
Docker installation on WSL2
Let's finally use Docker: Start, stop, delete development environment
BEAR application Docker development environment construction example (docker-sync, Mutagen)
Docker the development environment of Ruby on Rails project
Build Docker + Laravel PHP + Vue.js development environment in 5 minutes
[First team development ③] Share the development environment created with Docker
Try to build a Java development environment using Docker
Make the strongest Laravel development environment (Docker) Japan time
Comfortable Docker environment created with WSL2 CentOS7 and Docker Desktop
A memo when building a Rails 5.2 development environment using Docker Desktop + WSL2 on Windows 10 Home
Pytorch execution environment with Docker
Rails6 development environment construction [Mac]
Install / run a standalone robot simulator in wsl2 / docker environment!
Docker × Java Building a development environment that is too simple
I made a development environment with rails6 + docker + postgreSQL + Materialize.
[Docker] Create Elasticsearch, Kibana environment!
Organize your in-house development environment