This article is the 25th day of Fujitsu Advent Calendar 2020.
I got a development VM that can use Hypervisor so that Docker can be used for business, so I would like to install WSL2 (Windows Subsystem for Linux 2) so that Docker can be used so that it can be used effectively. However, since the Microsoft Store cannot be used, it will take some time. .. .. : scream:
An environment in which the Microsoft Store cannot be used is an environment in which the following window is displayed when the Microsoft Store is started.
First, enable WSL. Start Power Shell with administrator privileges and execute the following command. After execution, reboot.
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
Try the new cross-platform PowerShell https://aka.ms/pscore6
PS C:\WINDOWS\system32> dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
Deployment image services and management tools
version: 10.0.18362.1139
Image version: 10.0.18363.1198
The function is enabled
[==========================100.0%==========================]
The operation completed successfully.
Enable the virtual machine feature. Start Power Shell with administrator privileges and execute the following command. After execution, it will restart again.
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
Try the new cross-platform PowerShell https://aka.ms/pscore6
PS C:\WINDOWS\system32> dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
Deployment image services and management tools
version: 10.0.18362.1139
Image version: 10.0.18363.1256
The function is enabled
[==========================100.0%==========================]
The operation completed successfully.
Download and install the Linux kernel update package. You can download it from the following. wsl_update_x64.msi will be downloaded.
When the following window is displayed, the process is complete.
Make WSL2 the default version. Start Power Shell with administrator privileges and execute the following command.
wsl --set-default-version 2
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
Try the new cross-platform PowerShell https://aka.ms/pscore6
PS C:\WINDOWS\system32> wsl --set-default-version 2
For the main differences from WSL 2, https://aka.ms/See wsl2
The rest of the process will follow the steps in the information (Reference) previously shared by @ihgs.
Create a directory (WSL2 in this case) to store the distribution executable files directly under C: \ Program files.
cd ../../
mkdir Programfiles/WSL2
Download the distribution executable file from the Download Page (https://docs.microsoft.com/ja-jp/windows/wsl/install-manual#downloading-distros). This time I will download Ubuntu 18.04. Move the downloaded distribution executable file to the WSL2 directory you created earlier.
: warning: Ubuntu_1804.2019.522.0_x64.appx will be downloaded.
Start Power Shell with administrator privileges and change to the WSL2 directory you created earlier. Future steps will be carried out on this directory. First, rename the executable file and extract it. Execute the following command.
Rename-Item .\Ubuntu_1804.2019.522.0_x64.appx .\Ubuntu1804.zip
Expand-Archive .\Ubuntu1804.zip .\Ubuntu1804
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
Try the new cross-platform PowerShell https://aka.ms/pscore6
PS C:\WINDOWS\system32> cd ../../
PS C:\> mkdir '.\Program Files\WSL2'
directory: C:\Program Files Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2020/12/24 8:15 WSL2
PS C:\> cd '.\Program Files\WSL2'
PS C:\Program Files\WSL2> cp ..\..\Users\clouduser\Downloads\Ubuntu_1804.2019.522.0_x64.appx ./
PS C:\Program Files\WSL2> ls
directory: C:\Program Files\WSL2
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2020/12/18 17:23 231829509 Ubuntu_1804.2019.522.0_x64.appx
PS C:\Program Files\WSL2> Rename-Item .\Ubuntu_1804.2019.522.0_x64.appx .\Ubuntu1804.zip
PS C:\Program Files\WSL2> ls
directory: C:\Program Files\WSL2
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2020/12/18 17:23 231829509 Ubuntu1804.zip
PS C:\Program Files\WSL2> Expand-Archive .\Ubuntu1804.zip .\Ubuntu1804
PS C:\Program Files\WSL2> ls
directory: C:\Program Files\WSL2
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2020/12/24 8:16 Ubuntu1804
-a---- 2020/12/18 17:23 231829509 Ubuntu1804.zip
Move to the Ubuntu1804 directory created after extraction and execute ubuntu1804.exe
. The distribution installation will start. Finally, when the prompt UserName @ HostName $
is displayed, the process is complete.
cd .\Ubuntu1804\
.\ubuntu1804.exe
PS C:\Program Files\WSL2> cd .\Ubuntu1804\
PS C:\Program Files\WSL2\Ubuntu1804> ls
directory: C:\Program Files\WSL2\Ubuntu1804
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2020/12/24 8:16 AppxMetadata
d----- 2020/12/24 8:16 Assets
-a---- 2019/05/22 8:15 219038 AppxBlockMap.xml
-a---- 2019/05/22 8:15 3851 AppxManifest.xml
-a---- 2019/05/22 8:15 11209 AppxSignature.p7x
-a---- 2019/05/22 8:15 231179584 install.tar.gz
-a---- 2019/05/22 8:15 5400 resources.pri
-a---- 2019/05/22 8:15 211968 ubuntu1804.exe
-a---- 2019/05/22 8:15 744 [Content_Types].xml
PS C:\Program Files\WSL2\Ubuntu1804> .\ubuntu1804.exe
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: yuhkiyano
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Installation successful!
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.
yuhkiyano@Vectorfield-PC:~$
In WSL1, the network adapter was shared with the host machine, but it became a specification to communicate using a virtual network adapter independent of WSL2. This network adapter is a musician, and the IP address and MAC address change each time it is started. Therefore, communication is blocked by the firewall of the security software, so it is necessary to add settings. Also, configure Proxy settings as necessary. (I can't use apt and other applications that communicate with the outside world, and I'm struck by my nose ...)
Perform the upgrade with apt
.
sudo apt update && sudo apt upgrade -y
From here, install Docker Desktop for Windows. The settings on the WSL2 side are automatically executed when installing on Windows.
Download the Windows version of the Docker installer from Docker Desktop. The Docker Desktop Installer.exe
will be downloaded. Double-click when you are done. When the following window is displayed, just click OK.
When the installation is complete, click Close and Restart
to restart.
: warning: After restarting, Docker Desktop is starting
[^ docker] did not start easily, and finally a startup error was displayed. However, when I clicked Reset to Factory Default and Restart
!? [^ reset], Docker started with a plain face. When I searched the net, I found a similar issue, so it looks like a bug. .. ..
Set Proxy settings for Docker. It can be set from Settings> Resources> Proxies
. After completing the settings, execute the following command. Then the following warning is displayed. .. ..
$ docker container run --rm hello-world
Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: toomanyrequests: You have reached your pull rate limit. You may increase the limit by authenticating and upgrading: https://www.docker.com/increase-rate-limit.
See 'docker run --help'.
Apparently you need to log in with your Docker Hub account, so try logging in. .. ..
Log in at the command line and try running the hello-world
container again.
$ docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: ****
Password:
Login Succeeded
yuhkiyano:~ $ docker container run --rm hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete
Digest: sha256:1a523af650137b8accdaed439c17d684df61ee4d74feac151b5b337bd29e7eec
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
It was a success! !! : santa_tone1: This completes the construction of the environment where Docker can be executed from WSL2! !! : santa_tone2:
This time, I got a Windows 10 VM with Hyper-V enabled as a development environment, so I built a Docker environment. I didn't mention it because it is not the main point, but I struggled with the fact that communication was blocked by the firewall due to the characteristics of WSL2. Also, Docker Desktop has a lot of bugs. I just hope that it will be updated and resolved in the future. Anyway, Docker on Ubuntu 18.04 @ WSL2 has been completed, so I will use it.
To reinstall the distribution, run the following command to remove it from the wsl registration list and then delete the distribution directory.
Ubuntu18.When deleting 04
wsl --list
Windows subsystem distribution for Linux:
Ubuntu-16.04 (default)
Ubuntu-18.04
wsl --unregister Ubuntu-18.04
Since / mnt/c
is the C drive on the Windows side, you can access it.
$ sudo ls /mnt/c
'$Recycle.Bin'PerfLogs Recovery WSL setting backup wsl_settings
DTK 'Program Files' Squid Windows swapfile.sys
'Documents and Settings' 'Program Files (x86)' 'System Volume Information' pagefile.sys vscode_extension_install
MSOCache ProgramData Users public wsl_important_data
From VSCode If you have VSCode Remote Extension Pack installed, you can also access it from VSCode.
wsl --help
Copyright (c) Microsoft Corporation. All rights reserved.
how to use: wsl.exe [argument] [option...] [Command line]
Arguments for running Linux binaries:
If you don't specify a command line, wsl.The exe launches the default shell.
--exec, -e <Command line>
Runs the specified command without using the default Linux shell.
--
Pass the rest of the command line as is.
option:
--distribution, -d <Distribution>
Runs the specified distribution.
--user, -u <username>
Runs as the specified user.
Arguments for managing the Windows subsystem for Linux:
--export <Distribution> <file name>
Export the distribution to a tar file.
For standard output, enter the file name-Can be.
--import <Distribution> <Installation location> <file name> [option]
Imports the specified tar file as a new distribution.
For standard input, enter the file name-Can be.
option:
--version <version>
Specifies the version to use for the new distribution.
--list, -l [option]
Display a list of distributions.
option:
--all
Including those currently being installed or uninstalled
List all distributions.
--running
Lists only currently running distributions.
--quiet, -q
Shows only the distribution name.
--verbose, -v
View detailed information about all distributions.
--set-default, -s <Distribution>
Set the distribution as the default.
--set-default-version <version>
Change the default installation version for the new distribution.
--set-version <Distribution> <version>
Changes the version of the specified distribution.
--shutdown
Immediately shut down all running distributions and WSL 2 lightweight utility virtual machines.
--terminate, -t <Distribution>
Terminates the specified distribution.
--unregister <Distribution>
Unregister the distribution.
--help
Show usage.
Reference
[^ reset]: I don't think there's a reset or a mess on the first boot. .. .. This solved it. I admire that there are many places where I forgot to take a screen capture and only explained in sentences. .. .. [^ docker]: Docker Desktop is running and startup is complete.