【问题标题】:Cannot connect to the Docker daemon on debian buster on wsl 2无法连接到 wsl 2 上 debian buster 上的 Docker 守护程序
【发布时间】:2020-03-24 13:35:10
【问题描述】:

我正在尝试在 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
名称 国家 版本
* Debian 运行 2

$ cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (破坏者)"
VERSION_CODENAME=破坏者
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 服务码头工人状态
[FAIL] Docker 没有运行……失败了!

所以我尝试重新启动 docker daemon:

$ sudo service docker restart
grep: /etc/fstab: 没有这样的文件或目录
[ 好的 ] 启动 Docker:docker。

找到另一个 article on SO 说我可以通过发出以下命令来解决这个问题:

sudo touch /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

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


我遵循了下面@s-x-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 命令所期望的相同的目录结构。我没有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 以来 repo 已更改。如果有帮助,这里是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

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

【问题讨论】:

  • 您确定您使用的是 WSL2 吗?什么是完整的 Windows 10 版本号? Docker 守护进程需要从 systemd 启动。没有官方推荐的方法来做到这一点。你接受做一些“非官方”的命令吗?
  • 您好,谢谢您的回复。是的,它的 wsl 2,我更新了帖子以反映这一点,还包括 Windows10 内部版本号。如果它可以正常工作,我可以尝试任何leftfield。

标签: docker windows-subsystem-for-linux debian-buster wsl-2


【解决方案1】:

在这里发帖以防其他人像我一样遇到这个问题。好像和https://superuser.com/questions/1468316/which-kernel-moduules-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 服务。

【讨论】:

    【解决方案2】:

    我遇到了同样的问题,因为 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 run hello-world

    来自 Docker 的您好!

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

    【讨论】:

    • 感谢您的回复。我尝试了你的建议,但绊倒了。我相应地更新了上面的帖子。
    猜你喜欢
    • 2018-09-30
    • 1970-01-01
    • 1970-01-01
    • 2018-06-11
    • 2021-10-12
    • 2016-06-28
    • 2017-10-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多