在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

#先查询有哪些docker版本
apt-cache madison docker-ce

#安装最新版
sudo apt-get install -y docker-ce

#安装指定版要,比如安装5:19.03.6~3-0~ubuntu-bionic版本,-y参数有示非交互安装,有交互的时候自动传y参数。
sudo apt-get install -y docker-ce=5:19.03.6~3-0~ubuntu-bionic
 
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

原文地址:https://www.cnblogs.com/sfnz/p/15429096.html