1. 程式人生 > 其它 >在WINDOWS 10 WSL1 的子系統下完美解決DOCKER的命令問題

在WINDOWS 10 WSL1 的子系統下完美解決DOCKER的命令問題

在Windows 10 (1909)安裝了子系統ubuntu-20.04與windows-docker-2.3.0.3,在WSL1命令列下執行“docker ps”會出現如下問題:

The command 'docker' could not be found in this WSL 1 distro.
We recommend to convert this distro to WSL 2 and activate
the WSL integration in Docker Desktop settings.
 
See https://docs.docker.com/docker-for-windows/wsl/ for details.

解決方案

首先在docker setting上設定如下圖(紅圈鉤選中部份)

開啟Ubuntu Shell,執行以下命令:

wsl
 
sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
 
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
 
sudo apt remove gpg
 
sudo apt install gnupg1
 
sudo apt install software
-properties-common sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable" sudo apt-get -y update sudo apt-get -y install docker-ce echo "export DOCKER_HOST=tcp://localhost:2375" >> ~/.bashrc && source ~/.bashrc

然後重啟windows的Docker,

zhongyulin@LAPTOP-8SHV4IL8:~$ docker version
Client: Docker Engine - Community
 Version:           20.10.9
 API version:       1.41
 Go version:        go1.16.8
 Git commit:        c2ea9bc
 Built:             Mon Oct  4 16:08:29 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.7
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       b0f5bc3
  Built:            Wed Jun  2 11:54:58 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.6
  GitCommit:        d71fcd7d8303cbf684402823e425e9dd2e99285d
 runc:
  Version:          1.0.0-rc95
  GitCommit:        b9ee9c6314599f1b4a7f497e1f1f856fe433d3b7
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

參考:

https://www.freesion.com/article/17971075268/

https://www.cnblogs.com/yyee/p/12922221.html