There are two ways to use Docker on Windows

1. Install the WSL2 sub-Linux system, and install docker on the Linux sub-system

2. Run Docker directly without using WSL2 to start docker

  • Advantages of using WSL2 to install Docker: you can use the full Linux system. Disadvantages: Slow I/O and high memory usage
  • Do not use WSL2 to install Docker advantage: you can pull an Ubuntu image to use, quickly configure the development environment, disadvantages: temporarily unexpected

1. Use Windows Terminal PowerShell to enable Hyper-V

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All
Copy the code
  • After the installation, restart the operating system

  • How do I check whether Hyper-V is started after the restart
  1. Control Panel — Programs — Enable or disable Windows features

  1. When you see “Hyper-V”, check it and it’s on

2. Install the Docker Desktop for Windows

  • Uncheck WSL2

  1. When you open Docker Desktop, you are prompted that WSL2 is not installed. Select Hyper-V

4. Then the next step, the next step until the initialization is successful

3. The Docker Settings

  1. Click on the gear to set

  1. Example Set the image storage location

  1. Set the image acceleration, replace with the source of USTC, note that this is a JSON format, incorrect format will report an error

    1. Click Apply & Restart, then the docker Settings are complete, and then the Docker operation will be performed in Windows Terminal

4. Operate Docker in Windows Termial

  1. Enter docker, success if there are arguments

5. Pull out the Ubuntu image and configure it

  1. Pull the Ubuntu image
docker pull ubuntu
Copy the code
  1. After downloading it, run itdocker imagesTo view the local image
docker images
Copy the code
  1. Start a container, and run ubuntu bash inside the container
docker run -it ubuntu bash
Copy the code

  1. First update, install Sudo
apt update && apt upgrade
Copy the code
apt install sudo
Copy the code

5. Install common Linux command tools. -y is installed by default

sudo apt install -y zsh curl wget git fzf neovim ranger neofetch
Copy the code

6. Pack the image

  1. Exit in the container, we are now in the Windows Terminal command line window
  2. The inputdocker ps -a, output the exit mirror

3. Package the container into a new image. Note: since the image exits without repackaging, this will be initialized by default

docker commit 1444539f6bca ubuntu:version
Copy the code
  1. Take a look at your local mirror,docker images

5. Enter our custom image and launch the container command

docker run -it 1af71524afe3 zsh
Copy the code

Note that 1444539f6bca is the image ID of the custom image. If ZSH is installed on it, enter the shell of ZSH directly

To be continued, will be supplemented