在WSL2 Ubuntu 里面需要使用Docker的时候,发现一些应用对于WSL 内部Docker支持的不是很好,需要使用Docker Deskop来支持。但是在发布的时候出现了很多默认不使用Docker Desktop Docker的情况。
异常情况说明:
默认的docker驱动
jiangjh@DESKTOP-68F1OMN:~$ docker context ls
NAME DESCRIPTION DOCKER ENDPOINT ERROR
default * Current DOCKER_HOST based configuration unix:///var/run/docker.sock
desktop-linux Docker Desktop npipe:////./pipe/dockerDesktopLinuxEngine
jiangjh@DESKTOP-68F1OMN:~$ docker context use desktop-linux
desktop-linux
Current context is now "desktop-linux"
jiangjh@DESKTOP-68F1OMN:~$ kind get clusters
ERROR: failed to list clusters: command "docker ps -a --filter label=io.x-k8s.kind.cluster --format '{{.Label "io.x-k8s.kind.cluster"}}'" failed with error: exit status 1
Command Output: Failed to initialize: protocol not available
最后解决方案是通过拷贝windows的 kube配置到docker里面
mkdir -p ~/.kube
cp /mnt/c/Users/<你的用户名>/.kube/config ~/.kube/config
jiangjh@DESKTOP-68F1OMN:~$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
desktop-control-plane Ready control-plane 58m v1.31.1