在 WSL2 上的 Ubuntu 20.04 LTS 上,如果没有 sudo,则无法运行 docker

在 WSL2 上的 Ubuntu 20.04 LTS 上,如果没有 sudo,则无法运行 docker

https://github.com/sindresorhus/guides/blob/main/docker-without-sudo.md

找到了有关如何在没有 sudo 的情况下运行 docker 的文档,但由于某种原因它不起作用。我不知道为什么。

sudo groupadd docker

sudo gpasswd -a $USER docker

sudo service docker restart

我在 WSL Ubuntu 上运行了这三个命令,如果没有 sudo,就无法执行 docker run hello-world。

admin@PC-SE-L3056:~$ docker run hello-world
docker: Cannot connect to the Docker daemon at tcp://localhost:2375. Is the docker daemon running?.
See 'docker run --help'.
admin@PC-SE-L3056:~$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
cd latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:0fe98d7debd9049c50b597ef1f85b7c1e8cc81f59c8d623fcb2250e8bec85b38
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/

我在 WSL2 上使用 Ubuntu 20.04 LTS。

用户 admin 属于:

admin : admin adm dialout cdrom floppy sudo audio dip video plugdev netdev docker

我使用wsl --shutdownPowershell 重新启动了 WSL2。

相关内容