Docker 在 Windows WSL 上的 Ubuntu 中运行
我的错误
donhuvy@VYLAPTOP:~/temp2607/reaction-development-platform$ sudo apt-get update
Hit:1 https://download.docker.com/linux/ubuntu focal InRelease
Hit:2 http://archive.ubuntu.com/ubuntu focal InRelease
Get:3 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Hit:4 http://archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:5 http://archive.ubuntu.com/ubuntu focal-backports InRelease
Fetched 114 kB in 4s (26.4 kB/s)
Reading package lists... Done
W: Target Packages (stable/binary-amd64/Packages) is configured multiple times in /etc/apt/sources.list:50 and /etc/apt/sources.list.d/docker.list:1
W: Target Packages (stable/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:50 and /etc/apt/sources.list.d/docker.list:1
W: Target Translations (stable/i18n/Translation-en) is configured multiple times in /etc/apt/sources.list:50 and /etc/apt/sources.list.d/docker.list:1
W: Target CNF (stable/cnf/Commands-amd64) is configured multiple times in /etc/apt/sources.list:50 and /etc/apt/sources.list.d/docker.list:1
W: Target CNF (stable/cnf/Commands-all) is configured multiple times in /etc/apt/sources.list:50 and /etc/apt/sources.list.d/docker.list:1
W: Target Packages (stable/binary-amd64/Packages) is configured multiple times in /etc/apt/sources.list:50 and /etc/apt/sources.list.d/docker.list:1
W: Target Packages (stable/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:50 and /etc/apt/sources.list.d/docker.list:1
W: Target Translations (stable/i18n/Translation-en) is configured multiple times in /etc/apt/sources.list:50 and /etc/apt/sources.list.d/docker.list:1
W: Target CNF (stable/cnf/Commands-amd64) is configured multiple times in /etc/apt/sources.list:50 and /etc/apt/sources.list.d/docker.list:1
W: Target CNF (stable/cnf/Commands-all) is configured multiple times in /etc/apt/sources.list:50 and /etc/apt/sources.list.d/docker.list:1
donhuvy@VYLAPTOP:~/temp2607/reaction-development-platform$ sudo apt-get install docker-ce docker-ce-cli containerd.io
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
docker-ce-rootless-extras docker-scan-plugin pigz slirp4netns
Suggested packages:
aufs-tools cgroupfs-mount | cgroup-lite
The following NEW packages will be installed:
containerd.io docker-ce docker-ce-cli docker-ce-rootless-extras docker-scan-plugin pigz slirp4netns
0 upgraded, 7 newly installed, 0 to remove and 45 not upgraded.
Need to get 104 MB of archives.
After this operation, 448 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 https://download.docker.com/linux/ubuntu focal/stable amd64 containerd.io amd64 1.4.8-1 [24.7 MB]
Get:2 http://archive.ubuntu.com/ubuntu focal/universe amd64 pigz amd64 2.4-1 [57.4 kB]
Get:3 http://archive.ubuntu.com/ubuntu focal/universe amd64 slirp4netns amd64 0.4.3-1 [74.3 kB]
Get:4 https://download.docker.com/linux/ubuntu focal/stable amd64 docker-ce-cli amd64 5:20.10.7~3-0~ubuntu-focal [41.4 MB]
Get:5 https://download.docker.com/linux/ubuntu focal/stable amd64 docker-ce amd64 5:20.10.7~3-0~ubuntu-focal [24.8 MB]
Get:6 https://download.docker.com/linux/ubuntu focal/stable amd64 docker-ce-rootless-extras amd64 5:20.10.7~3-0~ubuntu-focal [9063 kB]
Get:7 https://download.docker.com/linux/ubuntu focal/stable amd64 docker-scan-plugin amd64 0.8.0~ubuntu-focal [3889 kB]
Fetched 104 MB in 17s (6216 kB/s)
Selecting previously unselected package pigz.
(Reading database ... 32256 files and directories currently installed.)
Preparing to unpack .../0-pigz_2.4-1_amd64.deb ...
Unpacking pigz (2.4-1) ...
Selecting previously unselected package containerd.io.
Preparing to unpack .../1-containerd.io_1.4.8-1_amd64.deb ...
Unpacking containerd.io (1.4.8-1) ...
Selecting previously unselected package docker-ce-cli.
Preparing to unpack .../2-docker-ce-cli_5%3a20.10.7~3-0~ubuntu-focal_amd64.deb ...
Unpacking docker-ce-cli (5:20.10.7~3-0~ubuntu-focal) ...
Selecting previously unselected package docker-ce.
Preparing to unpack .../3-docker-ce_5%3a20.10.7~3-0~ubuntu-focal_amd64.deb ...
Unpacking docker-ce (5:20.10.7~3-0~ubuntu-focal) ...
Selecting previously unselected package docker-ce-rootless-extras.
Preparing to unpack .../4-docker-ce-rootless-extras_5%3a20.10.7~3-0~ubuntu-focal_amd64.deb ...
Unpacking docker-ce-rootless-extras (5:20.10.7~3-0~ubuntu-focal) ...
Selecting previously unselected package docker-scan-plugin.
Preparing to unpack .../5-docker-scan-plugin_0.8.0~ubuntu-focal_amd64.deb ...
Unpacking docker-scan-plugin (0.8.0~ubuntu-focal) ...
Selecting previously unselected package slirp4netns.
Preparing to unpack .../6-slirp4netns_0.4.3-1_amd64.deb ...
Unpacking slirp4netns (0.4.3-1) ...
Setting up slirp4netns (0.4.3-1) ...
Setting up docker-scan-plugin (0.8.0~ubuntu-focal) ...
Setting up containerd.io (1.4.8-1) ...
Created symlink /etc/systemd/system/multi-user.target.wants/containerd.service → /lib/systemd/system/containerd.service.
Setting up docker-ce-cli (5:20.10.7~3-0~ubuntu-focal) ...
Setting up pigz (2.4-1) ...
Setting up docker-ce-rootless-extras (5:20.10.7~3-0~ubuntu-focal) ...
Setting up docker-ce (5:20.10.7~3-0~ubuntu-focal) ...
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /lib/systemd/system/docker.service.
Created symlink /etc/systemd/system/sockets.target.wants/docker.socket → /lib/systemd/system/docker.socket.
invoke-rc.d: could not determine current runlevel
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for systemd (245.4-4ubuntu3.6) ...
donhuvy@VYLAPTOP:~/temp2607/reaction-development-platform$ sudo docker run hello-world
docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'.
donhuvy@VYLAPTOP:~/temp2607/reaction-development-platform$ docker run
"docker run" requires at least 1 argument.
See 'docker run --help'.
Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
Run a command in a new container
donhuvy@VYLAPTOP:~/temp2607/reaction-development-platform$ docker --version
Docker version 20.10.7, build f0df350
donhuvy@VYLAPTOP:~/temp2607/reaction-development-platform$ docker run hello-world
docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'.
donhuvy@VYLAPTOP:~/temp2607/reaction-development-platform$ systemctl start docker
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
donhuvy@VYLAPTOP:~/temp2607/reaction-development-platform$ sudo dockerd
INFO[2021-07-26T09:26:04.598999900+07:00] Starting up
INFO[2021-07-26T09:26:05.751575600+07:00] libcontainerd: started new containerd process pid=4266
INFO[2021-07-26T09:26:05.751933800+07:00] parsed scheme: "unix" module=grpc
INFO[2021-07-26T09:26:05.752582200+07:00] scheme "unix" not registered, fallback to default scheme module=grpc
INFO[2021-07-26T09:26:05.752789000+07:00] ccResolverWrapper: sending update to cc: {[{unix:///var/run/docker/containerd/containerd.sock <nil> 0 <nil>}] <nil> <nil>} module=grpc
INFO[2021-07-26T09:26:05.753058600+07:00] ClientConn switching balancer to "pick_first" module=grpc
INFO[2021-07-26T09:26:05.784888200+07:00] starting containerd revision=7eba5930496d9bbe375fdf71603e610ad737d2b2 version=1.4.8
INFO[2021-07-26T09:26:05.807969400+07:00] loading plugin "io.containerd.content.v1.content"... type=io.containerd.content.v1
INFO[2021-07-26T09:26:05.809913000+07:00] loading plugin "io.containerd.snapshotter.v1.aufs"... type=io.containerd.snapshotter.v1
INFO[2021-07-26T09:26:06.359366500+07:00] skip loading plugin "io.containerd.snapshotter.v1.aufs"... error="aufs is not supported (modprobe aufs failed: exit status 1 \"modprobe: FATAL: Module aufs not found in directory /lib/modules/4.4.0-19041-Microsoft\\n\"): skip plugin" type=io.containerd.snapshotter.v1
INFO[2021-07-26T09:26:06.360318200+07:00] loading plugin "io.containerd.snapshotter.v1.btrfs"... type=io.containerd.snapshotter.v1
INFO[2021-07-26T09:26:06.361771600+07:00] skip loading plugin "io.containerd.snapshotter.v1.btrfs"... error="path /var/lib/docker/containerd/daemon/io.containerd.snapshotter.v1.btrfs (wslfs) must be a btrfs filesystem to be used with the btrfs snapshotter: skip plugin" type=io.containerd.snapshotter.v1
INFO[2021-07-26T09:26:06.362037500+07:00] loading plugin "io.containerd.snapshotter.v1.devmapper"... type=io.containerd.snapshotter.v1
WARN[2021-07-26T09:26:06.362243500+07:00] failed to load plugin io.containerd.snapshotter.v1.devmapper error="devmapper not configured"
INFO[2021-07-26T09:26:06.362974300+07:00] loading plugin "io.containerd.snapshotter.v1.native"... type=io.containerd.snapshotter.v1
INFO[2021-07-26T09:26:06.365365000+07:00] loading plugin "io.containerd.snapshotter.v1.overlayfs"... type=io.containerd.snapshotter.v1
INFO[2021-07-26T09:26:06.368026100+07:00] loading plugin "io.containerd.snapshotter.v1.zfs"... type=io.containerd.snapshotter.v1
INFO[2021-07-26T09:26:06.368363300+07:00] skip loading plugin "io.containerd.snapshotter.v1.zfs"... error="path /var/lib/docker/containerd/daemon/io.containerd.snapshotter.v1.zfs must be a zfs filesystem to be used with the zfs snapshotter: skip plugin" type=io.containerd.snapshotter.v1
INFO[2021-07-26T09:26:06.369411200+07:00] loading plugin "io.containerd.metadata.v1.bolt"... type=io.containerd.metadata.v1
WARN[2021-07-26T09:26:06.377457800+07:00] could not use snapshotter devmapper in metadata plugin error="devmapper not configured"
INFO[2021-07-26T09:26:06.378196300+07:00] metadata content store policy set policy=shared
INFO[2021-07-26T09:26:06.384144600+07:00] loading plugin "io.containerd.differ.v1.walking"... type=io.containerd.differ.v1
INFO[2021-07-26T09:26:06.384857900+07:00] loading plugin "io.containerd.gc.v1.scheduler"... type=io.containerd.gc.v1
INFO[2021-07-26T09:26:06.386379300+07:00] loading plugin "io.containerd.service.v1.introspection-service"... type=io.containerd.service.v1
INFO[2021-07-26T09:26:06.393867000+07:00] loading plugin "io.containerd.service.v1.containers-service"... type=io.containerd.service.v1
INFO[2021-07-26T09:26:06.394944900+07:00] loading plugin "io.containerd.service.v1.content-service"... type=io.containerd.service.v1
INFO[2021-07-26T09:26:06.395951300+07:00] loading plugin "io.containerd.service.v1.diff-service"... type=io.containerd.service.v1
INFO[2021-07-26T09:26:06.397012700+07:00] loading plugin "io.containerd.service.v1.images-service"... type=io.containerd.service.v1
INFO[2021-07-26T09:26:06.397965800+07:00] loading plugin "io.containerd.service.v1.leases-service"... type=io.containerd.service.v1
INFO[2021-07-26T09:26:06.398988200+07:00] loading plugin "io.containerd.service.v1.namespaces-service"... type=io.containerd.service.v1
INFO[2021-07-26T09:26:06.400056700+07:00] loading plugin "io.containerd.service.v1.snapshots-service"... type=io.containerd.service.v1
INFO[2021-07-26T09:26:06.401187500+07:00] loading plugin "io.containerd.runtime.v1.linux"... type=io.containerd.runtime.v1
INFO[2021-07-26T09:26:06.408917100+07:00] loading plugin "io.containerd.runtime.v2.task"... type=io.containerd.runtime.v2
INFO[2021-07-26T09:26:06.411047900+07:00] loading plugin "io.containerd.monitor.v1.cgroups"... type=io.containerd.monitor.v1
INFO[2021-07-26T09:26:06.412279400+07:00] loading plugin "io.containerd.service.v1.tasks-service"... type=io.containerd.service.v1
INFO[2021-07-26T09:26:06.412639500+07:00] loading plugin "io.containerd.internal.v1.restart"... type=io.containerd.internal.v1
INFO[2021-07-26T09:26:06.413666800+07:00] loading plugin "io.containerd.grpc.v1.containers"... type=io.containerd.grpc.v1
INFO[2021-07-26T09:26:06.414645100+07:00] loading plugin "io.containerd.grpc.v1.content"... type=io.containerd.grpc.v1
INFO[2021-07-26T09:26:06.415881400+07:00] loading plugin "io.containerd.grpc.v1.diff"... type=io.containerd.grpc.v1
INFO[2021-07-26T09:26:06.417013800+07:00] loading plugin "io.containerd.grpc.v1.events"... type=io.containerd.grpc.v1
INFO[2021-07-26T09:26:06.423490700+07:00] loading plugin "io.containerd.grpc.v1.healthcheck"... type=io.containerd.grpc.v1
INFO[2021-07-26T09:26:06.424583600+07:00] loading plugin "io.containerd.grpc.v1.images"... type=io.containerd.grpc.v1
INFO[2021-07-26T09:26:06.425780700+07:00] loading plugin "io.containerd.grpc.v1.leases"... type=io.containerd.grpc.v1
INFO[2021-07-26T09:26:06.426810700+07:00] loading plugin "io.containerd.grpc.v1.namespaces"... type=io.containerd.grpc.v1
INFO[2021-07-26T09:26:06.427972000+07:00] loading plugin "io.containerd.internal.v1.opt"... type=io.containerd.internal.v1
INFO[2021-07-26T09:26:06.430384700+07:00] loading plugin "io.containerd.grpc.v1.snapshots"... type=io.containerd.grpc.v1
INFO[2021-07-26T09:26:06.430569100+07:00] loading plugin "io.containerd.grpc.v1.tasks"... type=io.containerd.grpc.v1
INFO[2021-07-26T09:26:06.431579800+07:00] loading plugin "io.containerd.grpc.v1.version"... type=io.containerd.grpc.v1
INFO[2021-07-26T09:26:06.433089700+07:00] loading plugin "io.containerd.grpc.v1.introspection"... type=io.containerd.grpc.v1
INFO[2021-07-26T09:26:06.440447100+07:00] serving... address=/var/run/docker/containerd/containerd-debug.sock
INFO[2021-07-26T09:26:06.441881300+07:00] serving... address=/var/run/docker/containerd/containerd.sock.ttrpc
INFO[2021-07-26T09:26:06.443648400+07:00] serving... address=/var/run/docker/containerd/containerd.sock
INFO[2021-07-26T09:26:06.444409700+07:00] containerd successfully booted in 0.663149s
INFO[2021-07-26T09:26:06.458975000+07:00] parsed scheme: "unix" module=grpc
INFO[2021-07-26T09:26:06.459340200+07:00] scheme "unix" not registered, fallback to default scheme module=grpc
INFO[2021-07-26T09:26:06.459937000+07:00] ccResolverWrapper: sending update to cc: {[{unix:///var/run/docker/containerd/containerd.sock <nil> 0 <nil>}] <nil> <nil>} module=grpc
INFO[2021-07-26T09:26:06.461038500+07:00] ClientConn switching balancer to "pick_first" module=grpc
INFO[2021-07-26T09:26:06.464507500+07:00] parsed scheme: "unix" module=grpc
INFO[2021-07-26T09:26:06.465303100+07:00] scheme "unix" not registered, fallback to default scheme module=grpc
INFO[2021-07-26T09:26:06.465948100+07:00] ccResolverWrapper: sending update to cc: {[{unix:///var/run/docker/containerd/containerd.sock <nil> 0 <nil>}] <nil> <nil>} module=grpc
INFO[2021-07-26T09:26:06.469570200+07:00] ClientConn switching balancer to "pick_first" module=grpc
WARN[2021-07-26T09:26:06.508606600+07:00] Your kernel does not support cgroup memory limit
WARN[2021-07-26T09:26:06.509102200+07:00] Unable to find cpu cgroup in mounts
WARN[2021-07-26T09:26:06.509641700+07:00] Unable to find blkio cgroup in mounts
WARN[2021-07-26T09:26:06.511422700+07:00] Unable to find cpuset cgroup in mounts
WARN[2021-07-26T09:26:06.512210200+07:00] Unable to find pids cgroup in mounts
INFO[2021-07-26T09:26:06.513102200+07:00] Loading containers: start.
WARN[2021-07-26T09:26:06.525628500+07:00] Running iptables --wait -t nat -L -n failed with message: `iptables v1.8.4 (legacy): can't initialize iptables table `nat': Table does not exist (do you need to insmod?)
Perhaps iptables or your kernel needs to be upgraded.`, error: exit status 3
INFO[2021-07-26T09:26:06.633151400+07:00] stopping event stream following graceful shutdown error="<nil>" module=libcontainerd namespace=moby
INFO[2021-07-26T09:26:06.634747000+07:00] stopping healthcheck following graceful shutdown module=libcontainerdINFO[2021-07-26T09:26:06.634766100+07:00] stopping event stream following graceful shutdown error="context canceled" module=libcontainerd namespace=plugins.moby
WARN[2021-07-26T09:26:07.650886300+07:00] grpc: addrConn.createTransport failed to connect to {unix:///var/run/docker/containerd/containerd.sock <nil> 0 <nil>}. Err :connection error: desc = "transport: Error while dialing dial unix:///var/run/docker/containerd/containerd.sock: timeout". Reconnecting... module=grpc
failed to start daemon: Error initializing network controller: error obtaining controller instance: failed to create NAT chain DOCKER: iptables failed: iptables -t nat -N DOCKER: iptables v1.8.4 (legacy): can't initialize iptables table `nat': Table does not exist (do you need to insmod?)
Perhaps iptables or your kernel needs to be upgraded.
(exit status 3)
donhuvy@VYLAPTOP:~/temp2607/reaction-development-platform$ systemctl start docker
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
donhuvy@VYLAPTOP:~/temp2607/reaction-development-platform$ docker run hello-world
docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/create: dial unix /var/run/docker.sock: connect: permission denied.
See 'docker run --help'.
donhuvy@VYLAPTOP:~/temp2607/reaction-development-platform$ sudo rm -rf /etc/systemd/system/docker.service.d
donhuvy@VYLAPTOP:~/temp2607/reaction-development-platform$ sudo systemctl deamon-reload
Unknown operation deamon-reload.
donhuvy@VYLAPTOP:~/temp2607/reaction-development-platform$ systemctl status docker.service
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
donhuvy@VYLAPTOP:~/temp2607/reaction-development-platform$ sudo su
root@VYLAPTOP:/home/donhuvy/temp2607/reaction-development-platform# systemctl start docker
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down [ OK ]
root@VYLAPTOP:/home/donhuvy/temp2607/reaction-development-platform#
root@VYLAPTOP:/home/donhuvy/temp2607/reaction-development-platform#
Executing: /lib/systemd/systemd-sysv-install enable docker
root@VYLAPTOP:/home/donhuvy/temp2607/reaction-development-platform# systemctl restart docker
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
root@VYLAPTOP:/home/donhuvy/temp2607/reaction-development-platform# systemctl restart docker
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
root@VYLAPTOP:/home/donhuvy/temp2607/reaction-development-platform# systemctl restart docker
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
root@VYLAPTOP:/home/donhuvy/temp2607/reaction-development-platform# /etc/init.d/dbus start
root@VYLAPTOP:/home/donhuvy/temp2607/reaction-development-platform#
root@VYLAPTOP:/home/donhuvy/temp2607/reaction-development-platform#
root@VYLAPTOP:/home/donhuvy/temp2607/reaction-development-platform#
root@VYLAPTOP:/home/donhuvy/temp2607/reaction-development-platform# docker run hello-world
docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'.
root@VYLAPTOP:/home/donhuvy/temp2607/reaction-development-platform# service docker stop
* Docker already stopped - file /var/run/docker-ssd.pid not found.
root@VYLAPTOP:/home/donhuvy/temp2607/reaction-development-platform# cd /var/run/docker/libcontainerd
bash: cd: /var/run/docker/libcontainerd: No such file or directory
root@VYLAPTOP:/home/donhuvy/temp2607/reaction-development-platform# service docker start
* Starting Docker: docker [ OK ]
root@VYLAPTOP:/home/donhuvy/temp2607/reaction-development-platform#
root@VYLAPTOP:/home/donhuvy/temp2607/reaction-development-platform#
root@VYLAPTOP:/home/donhuvy/temp2607/reaction-development-platform#
root@VYLAPTOP:/home/donhuvy/temp2607/reaction-development-platform#
root@VYLAPTOP:/home/donhuvy/temp2607/reaction-development-platform#
root@VYLAPTOP:/home/donhuvy/temp2607/reaction-development-platform#
root@VYLAPTOP:/home/donhuvy/temp2607/reaction-development-platform# docker --version
Docker version 20.10.7, build f0df350
root@VYLAPTOP:/home/donhuvy/temp2607/reaction-development-platform# docker run hello-world
docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'.
root@VYLAPTOP:/home/donhuvy/temp2607/reaction-development-platform# docker run -v /var/run/docker.sock:/var/run/docker.sock
"docker run" requires at least 1 argument.
See 'docker run --help'.
Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
Run a command in a new container
root@VYLAPTOP:/home/donhuvy/temp2607/reaction-development-platform# make
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Removed docker development symlink for reaction-hydra
Running pre-build hook script for reaction-hydra.
reaction-hydra post-project-start script invoked.
/bin/sh: 1: docker-compose: not found
make: *** [Makefile:264: build-reaction-hydra] Error 127
root@VYLAPTOP:/home/donhuvy/temp2607/reaction-development-platform#
和
root@VYLAPTOP:/home/donhuvy/temp2607/reaction-development-platform# sudo systemctl is-active docker
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
root@VYLAPTOP:/home/donhuvy/temp2607/reaction-development-platform#
如何修复?
WSL 没有 init。您需要使用本机 Windows docker,它使用特殊的 WSL。
我寻找了这个问题的解决方案,我想你正在寻找的正是你想要的。我的目标是能够从我选择的 WSL 发行版 (Ubuntu) 中使用 docker。
- 确保您拥有 WSL2( 如何检查 )
- 下载 Docker Desktop (我知道你不想使用它,但请继续关注我)
- 打开 docker 桌面,转到设置、资源、WSL 集成。在这里激活与您选择的发行版的集成。
-
不要忘记点击
应用 &重新启动
-
现在打开您的 WSL 并输入
docker run hello-world
来测试 docker 是否正常工作
我还没有完全摆脱同样的错误(我使用 Windows 10、WSL2 和 Ubuntu 20.04,我当然不想使用名为 Docker Desktop 的蹩脚共享软件,它的所有升级和“Pro”废话都让我恼火)。
但是:遵循本指南 https://dev.to/bowmanjd/install-docker-on-windows-wsl-without-docker-desktop-34m9 似乎有所帮助。
我通过在
/etc/docker/daemon.json
配置中添加
"iptables": false
摆脱了与“iptables”相关的错误消息。不过,我刚才还没有设法启动
dockerd
(显然“错误创建默认“桥接”网络:权限被拒绝”有点困扰着我)。
如果愿意,可以尝试一下。
编辑: 出现错误消息的原因是,我的 WSL Ubuntu 20.04LTS 容器 - 尽管我是这样认为的 - 不是 WSL2 容器,而是 WSL。
确保将容器的版本设置为 v2 并确保使用该容器,可能将两个设置都设置为默认值(v2 和容器)。有关如何操作的详细信息,请参阅 https://stackoverflow.com/a/65005633/15610035 。
将容器的版本更改为 v2 后,错误消息消失。
但是:我目前无法让
dockerd
以 Windows 本地主机可以访问的方式公开端口,因为 WSL 本地主机与 Windows 本地主机不同。原因是,与 WSLv1 相比,WSLv2 处理网络的方式不同。
其他有用的文章: https://superuser.com/questions/1131874/how-to-access-localhost-of-linux-subsystem-from-windows 和 https://github.com/microsoft/WSL/issues/4150 。