Detailed process and problem solving of Docker installation under Windows

For personal study, there are errors and deficiencies welcome to point out and supplement.

Official manual for reference: https://docs.docker.com/desktop/windows/

Table of contents

One: What is Docker?

Two: Install Docker

(1) Install WSL2

(2) Install Docker Desktop for Windows

 (3) Change the mirror source

(4) Change the data storage location

1. Stop the docker service

2. Backup data to another folder 

3. Delete the original data

4. Change the data storage disk and restore the data

Three: The entanglement between Hype-v and the campus network 


One: What is Docker?

The following is an explanation from Wikipedia:

Docker  is an open source software and an open platform for developing applications, shipping applications, and running applications. Docker allows users to separate applications in the infrastructure (Infrastructure) to form smaller particles (containers), thereby increasing the speed of software delivery.

Docker containers are similar to virtual machines, but they differ in principle. Containers virtualize the operating system layer, and virtual machines virtualize hardware, so containers are more portable and efficiently utilize servers. Containers are more used to represent a standardized unit of software. Due to the standardization of containers, it can be deployed anywhere regardless of infrastructure differences. In addition, Docker also provides stronger industry isolation compatibility for containers.

Personal understanding:

1. The environment required for program operation can be quickly built.

2. The program and operating environment can be packaged to avoid the inability of the program to run due to lack of certain libraries or problems with environment variable settings. In other words, it solves the problem of why it works on my computer but not on other people's computers.

3.Docker only needs the required environment, occupies less resources than virtual machines, and is easier to operate than virtual machines.

Two: Install Docker

(1) Install WSL2

WSL, that is, Windows Subsystem on Linux, is called "Windows Subsystem for Linux" in Chinese. You can directly start a linux system in windows. Because docker relies on the linux kernel, it can only be used under linux. Windows needs to install a linux virtual machine to run, and Microsoft has built a lightweight virtual machine in win10. WSL2 is a complete linux running on the virtual machine. Kernel, so you need to use WSL2 to install docker.

Microsoft requires Windows 10 version 2004 and later (build 19041 and later) or Windows 11 

Settings -> Update & Security -> OS Build Information

Download the linux kernel required by wsl2:

URL:  https://docs.microsoft.com/zh-cn/windows/wsl/wsl2-kernel

Click to download the latest update package, and then double-click to run the installation.

Open the system virtual machine platform and WSL

Control Panel->Programs->Turn Windows Features on or off->Swipe down

To set WSL2 as the default version: Run Windows PowerShell as an administrator and run the command below.

wsl --set-default-version 2

(2) Install Docker Desktop for Windows

Some online tutorials are to install linux in WSL2 first, and then install docker. I don't have a lot of actual use needs yet, so I think it should be installed directly on the windows version.

Download and install the program from the official website: https://www.docker.com/get-started/

 

 After downloading, just double-click to run the installation (it is recommended not to use the campus network during installation, otherwise there may be some problems, which I will explain later).

Check the wsl2-based engine in the settings (my default is checked)

Running wsl -l -v with PowerShell  will find that two distributions have been created

The installation is complete here

 (3) Change the mirror source

It is often more touching to pull images from the official DockerHub in China, so we need to use domestic image sources or accelerators

HKUST Mirror: https://docker.mirrors.ustc.edu.cn/
Netease: https://hub-mirror.c.163.com/

{
  "registry-mirrors": [
    "https://1nj0zren.mirror.aliyuncs.com",
    "https://docker.mirrors.ustc.edu.cn",
    "http://f1361db2.m.daocloud.io",
    "https://registry.docker-cn.com"
  ],
  "insecure-registries": [],
  "debug": true,
  "experimental": false
}

 You can also use Alibaba Cloud, which needs to be obtained from the official website of Alibaba Cloud.

After configuring a certain image source address, if you find that the image cannot be pulled, just switch to another address.

(4) Change the data storage location

The docker under Windows is installed on the C drive by default, so in order to save our poor C drive, we need to store the data in other drives.

1. Stop the docker service

2. Backup data to another folder 

PowerShellRun

wsl --export docker-desktop-data "E:\DockerData\docker-desktop-data.tar"

 

3. Delete the original data

wsl --unregister docker-desktop-data

 

4. Change the data storage disk and restore the data

wsl --import docker-desktop-data "E:\DockerData" "E:\DockerData\docker-desktop-data.tar" --version 2

The backup data is about to be imported to a new virtual disk, and the storage path of the specified virtual disk is E:\DockerData. After the import is completed, there will be a virtual disk path of ext4.vhdx in this directory

Then start docker

The operation here is borrowed from a big guy, the original address: https://www.cnblogs.com/shanyou/p/14284309.html

Three: The entanglement between Hyper-v and the campus network 

When I installed docker and was about to experience it, the lovely campus website gave me a big mouth:

 It also seemed to be very "intimate" and told me that the reason for the disconnection was that the Hyper-V network card had a conflict with it.

But for the sake of the network, I also want to keep Hyper-V (all installation tutorials will tell you that the operation of docker depends on it), and at the same time, I wonder if this gateway can be deleted to solve this problem. I tried the online Hyper-V Remove or uninstall, or even delete the registry, but the gateway will still be restored when restarting or using the Hyper-V service.

There are very few solutions to this problem on the Internet (Is it just me?), I searched on the Internet and said that docker depends on Hyper-V, and WSL2 also depends on Hyper-V, so I always think that Hyper-V is the absolute core indispensable. But after many attempts, I found that docker
can be started by relying on WSL alone, but the function is not
complete. It can be used by relying on Hyper-V alone, but it will disconnect the network
. It can be used by relying on WSL2 alone, and it will not disconnect the network.

And the network card used in the control panel is:

 Although it also says Hyper-V, it should be a virtual machine with streamlined functions. After various attempts and restarts, I found that after manually disabling this network card, the campus network can be connected normally, and docker can also run.

I thought the problem was solved, but it turned out that after the computer was restored, docker could no longer run (it returned to normal after restarting the network card, but the campus network could not be connected again), and the network card would restart every time the computer was restarted. It is indeed a headache to manually turn off the network card every time the computer is restarted and restart the network every once in a while.

Well, after so much tossing, I didn't find a very effective solution. It really doesn't work. Let's use it in the linux virtual machine in the future. 

Guess you like

Origin blog.csdn.net/m0_68988603/article/details/123884239