I followed the document Windows Subsystem for Linux Installation Guide for Windows 10
My environment is Windows 10 Pro 20H2 OS build 19042.685
Run powershell.exe as administrator.
Then enable the Windows Subsystem for Linux.
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
And enable Virtual Machine feature
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
Download the Linux kernel update package and install it.
- WSL2 Linux kernel update package for x64 machines
Set WSL 2 as the default version
wsl --set-default-version 2
Install Linux distribution from Microsoft Store
Then launch it.
I could not launch it for a long time because of bug of COMODO Internet Security shown at WSL2 Converstion Failed with Error: 0x80041002
COMODO released new version for fixing it
Installing, this may take a few minutes...
Please create a default UNIX user account. The username does not need to match your Windows username.
For more information visit: https://aka.ms/wslusers
Enter new UNIX username: xxxx
New password:
Retype new password:
passwd:
password updated successfully
Installation successful!
$ uname -a
Linux xxxxxxxxxxxxxxx 4.19.128-microsoft-standard #1 SMP Tue Jun 23 12:58:10 UTC 2020 x86_64 GNU/Linux
$ cat /etc/debian_version
10.8
$ df -k
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sdb 263174212 280972 249455084 1% /
tmpfs 3161096 0 3161096 0% /mnt/wsl
tools 248559384 53031224 195528160 22% /init
none 3158696 0 3158696 0% /dev
none 3161096 4 3161092 1% /run
none 3161096 0 3161096 0% /run/lock
none 3161096 0 3161096 0% /run/shm
none 3161096 0 3161096 0% /run/user
tmpfs 3161096 0 3161096 0% /sys/fs/cgroup
C:\ 248559384 53031224 195528160 22% /mnt/c
From next time, we can launch it with command 'debian'.
Also we can launch it with wsl command on command prompt or powershell.
> wsl --list --verbose
NAME STATE VERSION
* Debian Stopped 2
> wsl -d Debian
> wsl -d Debian -e uname -a
We can omit distribution name for the default one.
> wsl
> wsl -e uname -a
We can just execute bash shell or bash shell script as below.
> bash
> bash -c "echo uname -a > test.sh"
> bash -c "./test.sh"
export and import a distribution
> wsl --export debian d:\debian.tar.gz
> wsl --import mydebian d:\wsl\ d:\debian.tar.gz
> wsl --list -v
set new distribution as a default one and set default user.
> wsl --set-default mydebian
> wsl
# If the user does not exist in this distribution, you have to create it.
echo -e "[user]\ndefault=myUsername" >> /etc/wsl.conf
exit
> wsl --shutdown
> wsl
delete distribution
> wsl --unregister debian-work
> wsl --list -v
install docker in wsl2 debian environment
We can install newest release as https://docs.docker.com/engine/install/debian/
But I prefered to install from debian package
sudo apt update
sudo apt install --no-install-recommends docker.io
sudo service docker start
sudo service docker status
At this point, I could not start dockerd.
I followed this flow https://github.com/microsoft/WSL/discussions/4872#discussioncomment-99164
sudo touch /etc/fstab
sudo update-alternatives --set iptables /usr/sbin/iptables-legacy
sudo update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy
sudo service docker start
sudo service docker status
Succeeded to start dockerd.
sudo docker run --rm -it debian:bullseye-slim
resolve domain name lookup failure problem
This workaround resolve domain name lookup failure problem on WSL2 and docker container.
https://github.com/microsoft/WSL/issues/4285#issuecomment-522201021
Add these lines in /etc/wsl.conf on your distribution
[network]
generateResolvConf = false
Then shutdown wsl2 and restart your distribution
> wsl --shutdown
> wsl --list -v
Recreate /etc/resolv.conf
$ sudo rm /etc/resolv.conf
$ echo "nameserver 1.1.1.1" > /etc/resolv.conf
Then shutdown wsl2 and restart your distribution again
> wsl --shutdown
> wsl --list -v
Confirm your setting and domain name lookup on your distribution and docker container.
$ cat /etc/resolv.conf
$ curl -I www.google.com