3

我正在尝试在 Windows Subsystem for Linux (WSL) 2 上安装 docker(在 Windows Home build 19033.1 上运行)。我按照https://docs.microsoft.com/en-us/windows/wsl/wsl2-install上的说明安装了 wsl2,并从 Windows Store 安装了 debian,即 debian 10(buster)。它在 wsl 2 上运行,如下所示:

wsl -l -v
NAME STATE VERSION
* Debian Running 2

$ cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=debian
HOME_URL=" https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

我按照https://linuxconfig.org/how-to-install-docker-on-debian-10-buster-linux的说明安装 docker:

sudo apt install docker.io
sudo docker run hello-world docker
:无法连接到 unix:///var/run/docker.sock 上的 Docker 守护进程。docker 守护进程是否正在运行?

查看docker是否正在运行:

sudo service docker status
[FAIL] Docker 没有运行……失败了!

所以我尝试重新启动docker守护进程:

$ sudo service docker restart
grep: /etc/fstab: No such file or directory
[ ok ] 启动 Docker: docker.

在 SO 上找到另一篇文章说我可以通过发布来解决这个问题:

须藤触摸 /etc/fstab

这似乎有效(不再出现grep错误):

$ sudo service docker restart
[ ok ] 启动 Docker:docker.

但我仍然遇到同样的问题:

$ sudo docker run hello-world
docker:无法连接到 unix:///var/run/docker.sock 上的 Docker 守护进程。docker 守护进程是否正在运行?

我查看了 docker 日志,里面充满了错误:

$ cat /var/log/docker.log | grep -i error  
time="2019-11-28T21:48:51.725383200Z" level=warning msg="failed to load plugin io.containerd.snapshotter.v1.btrfs" error="path /var/lib/docker/containerd/daemon/io.containerd.snapshotter.v1.btrfs must be a btrfs filesystem to be used with the btrfs snapshotter"  
time="2019-11-28T21:48:51.726777600Z" level=warning msg="failed to load plugin io.containerd.snapshotter.v1.aufs" error="modprobe aufs failed: \"modprobe: ERROR: ../libkmod/libkmod.c:586 kmod_search_moddep() could not open moddep file '/lib/modules/4.19.84-microsoft-standard/modules.dep.bin'\\nmodprobe: FATAL: Module aufs not found in directory /lib/modules/4.19.84-microsoft-standard\\n\": exit status 1"  
time="2019-11-28T21:48:51.726982500Z" level=warning msg="failed to load 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"  
time="2019-11-28T21:48:51.727010800Z" level=warning msg="could not use snapshotter aufs in metadata plugin" error="modprobe aufs failed: \"modprobe: ERROR: ../libkmod/libkmod.c:586 kmod_search_moddep() could not open moddep file '/lib/modules/4.19.84-microsoft-standard/modules.dep.bin'\\nmodprobe: FATAL: Module aufs not found in directory /lib/modules/4.19.84-microsoft-standard\\n\": exit status 1"  
time="2019-11-28T21:48:51.727022700Z" level=warning msg="could not use snapshotter zfs in metadata plugin" error="path /var/lib/docker/containerd/daemon/io.containerd.snapshotter.v1.zfs must be a zfs filesystem to be used with the zfs snapshotter"  
time="2019-11-28T21:48:51.727031100Z" level=warning msg="could not use snapshotter btrfs in metadata plugin" error="path /var/lib/docker/containerd/daemon/io.containerd.snapshotter.v1.btrfs must be a btrfs filesystem to be used with the btrfs snapshotter"  
time="2019-11-28T21:48:51.744791900Z" level=warning msg="Running modprobe nf_nat failed with message: `modprobe: ERROR: ../libkmod/libkmod.c:586 kmod_search_moddep() could not open moddep file '/lib/modules/4.19.84-microsoft-standard/modules.dep.bin'\nmodprobe: WARNING: Module nf_nat not found in directory /lib/modules/4.19.84-microsoft-standard`, error: exit status 1"  
time="2019-11-28T21:48:51.746095200Z" level=warning msg="Running modprobe xt_conntrack failed with message: `modprobe: ERROR: ../libkmod/libkmod.c:586 kmod_search_moddep() could not open moddep file '/lib/modules/4.19.84-microsoft-standard/modules.dep.bin'\nmodprobe: WARNING: Module xt_conntrack not found in directory /lib/modules/4.19.84-microsoft-standard`, error: exit status 1"  
time="2019-11-28T21:48:51.768996800Z" level=info msg="stopping event stream following graceful shutdown" error="<nil>" module=libcontainerd namespace=moby  
time="2019-11-28T21:48:51.769171500Z" level=info msg="stopping event stream following graceful shutdown" error="context canceled" module=libcontainerd namespace=plugins.moby
Error starting daemon: Error initializing network controller: error obtaining controller instance: failed to create NAT chain DOCKER: iptables failed: iptables --wait -t nat -N DOCKER: iptables v1.8.2 (nf_tables):  CHAIN_ADD failed (No such file or directory): chain PREROUTING

有点迷失了这里的问题。希望有人可以建议?


我遵循了下面@sx-tan 的出色建议,他建议遵循https://kind.sigs.k8s.io/docs/user/using-wsl2/#updating-kernel上的说明。这些说明说要发布:

# This assumes Ubuntu or Debian, a different step may be needed for RPM based distributions
sudo apt install build-essential flex bison libssl-dev libelf-dev
git clone --depth 1 https://github.com/microsoft/WSL2-Linux-Kernel.git
cd WSL2-Linux-Kernel
make -j4 KCONFIG_CONFIG=Microsoft/config-wsl
mkdir /mnt/c/linuxtemp
cp arch/x86_x64/boot/bzImage /mnt/c/linuxtemp/

cp不幸的是,这些命令不会产生与该命令所期望的相同的 dir 结构。我没有arch/x86_x64/目录。我确实有一个arch/x86目录,但不包含boot/bzImage

jamiet@DESKTOP-GA45TGH:/mnt/c/Users/jamie/git/github/microsoft/WSL2-Linux-Kernel$ ls arch/x86/boot/
a20.c       code16gcc.h  cpuflags.h              install.sh      pm.c      string.h      video.c
apm.c       compressed   ctype.h                 main.c          pmjump.S  tools         video.h
bioscall.S  copy.S       early_serial_console.c  Makefile        printf.c  tty.c         video-mode.c
bitops.h    cpu.c        edd.c                   memory.c        regs.c    version.c     video-vesa.c
boot.h      cpucheck.c   genimage.sh             mkcpustr.c      setup.ld  vesa.h        video-vga.c
cmdline.c   cpuflags.c   header.S                mtools.conf.in  string.c  video-bios.c

我遵循了确切的说明,因此只能猜测自从编写了https://kind.sigs.k8s.io/docs/user/using-wsl2/#updating-kernel以来,回购已经发生了变化。如果它有帮助,这里是目录arch

jamiet@DESKTOP-GA45TGH:/mnt/c/Users/jamie/git/github/microsoft/WSL2-Linux-Kernel$ ls arch/
alpha  arm    c6x    hexagon  Kconfig  microblaze  nds32  openrisc  powerpc  s390  sparc  unicore32  xtensa
arc    arm64  h8300  ia64     m68k     mips        nios2  parisc    riscv    sh    um     x86

仍然希望有人能澄清一下。

4

2 回答 2

4

在这里发帖以防其他人像我一样遇到这个问题。这似乎与https://superuser.com/questions/1468316/which-kernel-modules-are-really-needed-for-docker-installation相同的问题

根据该答案,运行后:

sudo update-alternatives --set iptables /usr/sbin/iptables-legacy
sudo update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy

我能够启动 docker 服务。

于 2020-10-26T20:52:56.533 回答
1

我遇到了同样的问题,因为 Debian 没有安装4.19.84-microsoft-standard内核的模块。不幸的是,微软没有为此内核提供预构建的 lib/modules,您必须使用来自https://github.com/microsoft/WSL2-Linux-Kernel的源代码来构建内核。

我尝试了从 Debian 映像中提取的内核 4.9.0-11-amd64 作为自定义内核(在 .wslconfig 中),但 WSL2 无法启动它。所以没有其他办法。

以下是说明: https ://kind.sigs.k8s.io/docs/user/using-wsl2/#updating-kernel

构建内核后,运行sudo make modules_install,然后运行 ​​docker:

*docker运行你好世界

来自 Docker 的您好!

此消息表明您的安装似乎工作正常。*

于 2019-12-05T03:21:58.767 回答