Install Linux virtual machine (wsl2) and docker under windows.

cy_ b 2022-01-15 01:47:13

One 、windows terminal( Important tools , But you can also not install )

This is the terminal tool officially recommended by Microsoft , similar mac Of iterm2, Multiple terminals can be started at the same time , At first, the default is power shall,cmd, Downloadable gsudo Integrate PowerShall( Administrators ), installed wsl(linux) after , The system will also be automatically integrated into the options .

Install and start setup Windows terminal Microsoft official website link . The selfie party can customize the theme , Background, etc . There are quite a few related tutorials .

Set up PowerShall( Administrators ):

gsudo - github

You can also directly enter the command to download

winget install gsudo

stay json Add... To the configuration file

"commandline": "gsudo.exe powershell.exe",
"guid": "{41dd7a51-f0e1-4420-a2ec-1a7130b7e950}",
"hidden": false,
"name": "Windows PowerShell Elevated"


Two 、 install wsl

With {Ubuntu} It refers to... To be downloaded linux System version ,wsl2 Default Ubuntu.

prerequisite :

1. Find... In system settings “Turn Windows features on or off”( Turn on or off Windows function ), Choose Hyper-V、Virtual Machine Platform、Windows Hypervisor Platform( Apply to Linux Of Windows Subsystem 、 Virtual machine platform ) Three options . Confirm opening , restart .

2. Make sure that the BIOS Enable virtualization... In . You can search and enter according to the model of the computer manufacturer bios Method ( Press a key wildly when turning on ), And how to set up .

3. Need to be in PowerShall( Administrators ) Run all commands .

install :

wsl2 comparison wsl1 Simplifies installation operations , Now just use the command directly to install .

wsl --install

Such as wsl already installed , Deleted by mistake linux System , You can use the following command to find the downloadable version and download it again . You can also go directly to the Microsoft Store to find downloads .

wsl --list --online
wsl --install -d {Ubuntu}

The installation will pop up {Ubuntu} window , Automatic download , Wait a moment, don't close the window , When the download is complete , Fill in linux Initialize the account and password ( Initialized here is linux User's account password .su The password required for the command , namely root The user's initial password is not set , Need to be behind liunx Terminal use command “sudo passwd root” modify )

install WSL Microsoft official website link .

Get into linux virtual machine :

installed wsl after , Can be found in powershall Medium output wsl, Get into wsl Set the default linux virtual machine .


sign out

It can also be in windows terminal Into

Or open it directly

Mount disk

Directly installed linux In the system , Will mount the local computer's folder to /mnt/ In the folder ,C Disk correspondence /mnt/c,D Disk correspondence /mnt/d, And so on . If you want to change the mount Directory , You can use the following command . With / Folder as an example .

sudo mkdir /c
sudo umount /mnt/d
sudo mount -t drvfs C: /c


Microsoft Store installation linux Method :


3、 ... and 、 install docker


install windows Version of the client docker, Support needs to be enabled in the client wsl2 The option to .

WSL 2 Upper Docker Getting started with remote containers   Microsoft official website link .

Visual client is very convenient , But in windows Upper docker Not in linux Used in virtual machines , It also means you use docker Basically say goodbye to the command line . Also note that in windows In the system , Set the mount disk to Set shared file permissions , Otherwise it would be a little strange bug.


Direct download docker It may not be the latest version , Recommended reference docker The official website tutorial installation :docker Official website installation documents (Ubuntu)

Check the installation

notes : Use docker when , The port needs to be explicitly mounted , Otherwise you need to use docker-machine Check the corresponding random local port ( perhaps windows View directly in the client )


docker-compose Recommended pip install ,pip Is based on python Package installer for . Attention should be paid to ,linux Default in virtual machine python The version is 2.7, We need to download and change the default to 3,pip Also have python and python3 Two versions , Need to use python3 Version of .

Change the system default python edition :

apt-get install python3
sudo rm -rf python
sudo ln -s /usr/bin/python3 /usr/bin/python

  install pip3

sudo apt-get install python3-pip

install docker-compose

pip install docker-compose

Check version

notes :pip Appears when installing the software Command "python egg_info" failed with error code 1 in /tmp/pip-build*

sudo python -m pip install --upgrade --force pip
sudo pip install setuptools==33.1.1


Similar articles