I installed WSL2 without using Microsoft Store and tried to build an environment where Docker can be used

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:

Can't use Microsoft Store? ??

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.

store block.jpg

Environmental information

Enable WSL2

Enable WSL

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
Execution result
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 virtual machine functionality

Enable the virtual machine feature. Start Power Shell with administrator privileges and execute the following command. After execution, it will restart again.

Required environmental requirements

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
Execution result
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 the Linux kernel update package

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.

kernelwsl.jpg

WSL2 is the default version

Make WSL2 the default version. Start Power Shell with administrator privileges and execute the following command.

wsl --set-default-version 2
Execution result
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

Distribution setup

The rest of the process will follow the steps in the information (Reference) previously shared by @ihgs.

Create a directory to store the distribution's executable files

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

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.

Extracting the distribution executable file

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
Execution result
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

Installation of distribution (execution of executable file)

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
Execution result
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:~$

Firewall and Proxy settings

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 ...)

OS upgrade

Perform the upgrade with apt.

sudo apt update && sudo apt upgrade -y

Docker installation

From here, install Docker Desktop for Windows. The settings on the WSL2 side are automatically executed when installing on Windows.

Download installer

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.

start_install.jpg

installing.jpg

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. .. ..

Proxy settings and login to Docker Hub

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. .. ..

dockerhublogin.jpg

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:

Summary

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.

Other tips

When reinstalling

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

I want to access the C drive on the Windows side

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.

wsl2vscode.jpg

WSL command option list

Option list
 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.

Recommended Posts

I installed WSL2 without using Microsoft Store and tried to build an environment where Docker can be used
I tried to build an environment using Docker (beginner)
I tried to build the environment little by little using docker
I tried to build the environment of WSL2 + Docker + VSCode
Build an environment where pip3 can be used with CentOS7 + Python3
Create an environment where CircleCI can be executed locally with Windows10 + WSL2 (Ubuntu) + Docker
I want to build Java Applet without using an IDE
How to change Java version and execute in an environment where Java cannot be installed freely
I tried to integrate Docker and Maven / Netbean nicely using Jib
I tried to build the environment of PlantUML Server with Docker
I tried to build an http2 development environment with Eclipse + Tomcat
I tried to build a laravel operating environment while remembering Docker
I introduced WSL2 + Ubuntu to Window10 and tried using GDC, DMD, LDC
I tried to build a Firebase application development environment with Docker in 2020
01. I tried to build an environment with SpringBoot + IntelliJ + MySQL (MyBatis) (Windows10)
When I tried to build an environment of PHP7.4 + Apache + MySQL with Docker, I got stuck [Windows & Mac]
[Rails] How to build an environment with Docker
Check if a string can be converted to an int without using Integer # parseInt
I tried using Wercker to create and publish a Docker image that launches GlassFish 5.
Compiled kotlin with cli with docker and created an environment that can be executed with java
[Road _node.js_1-1] Road to build Node.js Express MySQL environment using Docker
I built an Ubuntu environment on Windows 10 using WSL2.
Easily build Redmine on Windows using WSL2 and Docker
Rails6 I tried to introduce Docker to an existing application
Try to build a Java development environment using Docker
I tried using Docker because I don't want to pollute the local environment in Microsoft Teams tab development of MS Learn
[Rails 6.0, Docker] I tried to summarize the Docker environment construction and commands necessary to create a portfolio
How to create an environment that uses Docker (WSL2) and Vagrant (VirtualBox) together on Windows
I tried to build an API server with Go (Echo) x MySQL x Docker x Clean Architecture
I was addicted to WSl when trying to build an android application development environment with Vue.js
I tried to make an introduction to PHP + MySQL with Docker
What happened in "Java 8 to Java 11" and how to build an environment
I tried to create React.js × TypeScript × Material-UI on docker environment
Build a Node-RED environment with Docker to move and understand
[Rails] I tried to implement "Like function" using rails and js
I tried to create a padrino development environment with Docker
After learning Progate, I tried to make an SNS application using Rails in the local environment
Build docker environment with WSL
[App development 0.5] [Node.js express Docker] Build an environment for Node.js Express MongoDB using Docker
How to install the language used in Ubuntu and how to build the environment
I tried to build a simple application using Dockder + Rails Scaffold
I tried to see if Koalas and Elasticsearch can work together
I tried to make it an arbitrary URL using routing nesting
About the range and scope where Day16 variables can be used
I tried to make a machine learning application with Dash (+ Docker) part1 ~ Environment construction and operation check ~
Pg_resetwal can be used to start the PostgreSQL Docker container when WAL is broken and cannot be started.