Ubuntu-22.04与安装的Docker Desktop连不上的问题及解决
作者:众乐乐_2008
文章说明在Ubuntu WSL1中运行dockerps报错,因版本不匹配导致Docker命令缺失,解决方法包括:将WSL默认版本改为2,启用Docker Desktop的WSL2集成,重启WSL后测试,即可正常查看容器
ubuntu中运行“docker ps”的报错
root2@DESKTOP-0EV15EN:~$ 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. For details about using Docker Desktop with WSL 2, visit: https://docs.docker.com/go/wsl2/
问题是
wsl版本不对。
ubuntu是1,Docker Desktop是2 ,于是一番操作:
在 **PowerShell(管理员)**里运行:
wsl --set-version Ubuntu-22.04 2
如果想以后新安装的 WSL 发行版默认就是 WSL2,可以执行:
wsl --set-default-version 2
再然后
1.打开 Docker Desktop → Settings → Resources → WSL Integration
勾选 Ubuntu-22.04
。
2.关闭再进入 WSL:
wsl --shutdown wsl -d Ubuntu-22.04
3.测试:
docker ps
4.这时候就能在 Ubuntu-22.04 里看到 Docker Desktop 的容器了。
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。