wsl 安装完docker后,启动报错 WSL Docker : Cannot connect to the Docker daemon at unix:///var/run/docker.sock

问题原因:wsl1 对docker的支持不完善,需要切换到wsl2

#查看wsl版本

C:> wsl.exe -l -v
NAME STATE VERSION
* Ubuntu-20.04 Running 1
docker-desktop-data Running 2
docker-desktop Running 2

2、切换到wsl2

C:> wsl.exe --set-version ubuntu-20.04 2
正在进行转换,这可能需要几分钟时间...
有关与 WSL 2 的主要区别的信息,请访问 https://aka.ms/wsl2
转换完成。

3、切换成功后,重启docker 

nineday$ sudo service docker stop
nineday$ sudo service docker start
 * Starting Docker: docker                                                 [ OK ]

4、启动hello-world 

nineday$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:9f6ad537c5132bcce57f7a0a20e317228d382c3cd61edae14650eec68b2b345c
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

参考链接

https://www.cnblogs.com/wxw310415/p/14660690.html

猜你喜欢

转载自blog.csdn.net/u013240609/article/details/118001624