在Windows子系统Linux上运行Ubuntu上的Docker

问题描述 投票:7回答:5

我试图在WSL上运行Docker失败。我按照给install Docker on Ubuntu的步骤在WSL上安装了Docker,但是当我执行docker ps时,我收到以下错误:

docker ps    
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

看着码头日志我发现了这个:

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.4.0-43-Microsoft/modules.dep.bin'\nmodprobe: WARNING: Module nf_nat not found in directory /lib/modules/4.4.0-43-Microsoft`, error: exit status 1"
time="2017-12-28T12:07:23.227671600+01:00" 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.4.0-43-Microsoft/modules.dep.bin'\nmodprobe: WARNING: Module xt_conntrack not found in directory /lib/modules/4.4.0-43-Microsoft`, error: exit status 1"
Error starting daemon: Error initializing network controller: error obtaining controller instance: failed to create NAT chain: iptables failed: iptables -t nat -N DOCKER: iptables v1.6.0: 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)

知道如何在WSL上运行Docker?

windows docker windows-subsystem-for-linux
5个回答
12
投票

最后,我可以轻松地在WSL上运行Docker:首先需要在Windows上安装和运行Docker Engine,然后在Ubuntu bash上创建一个指向Windows可执行文件的符号链接:

sudo ln -s /mnt/c/Program\ Files/Docker/Docker/resources/bin/docker.exe /usr/bin/docker

此链接有效,因为从Windows 10 Creators Update版本可以从Bash运行Windows可执行文件。如果Windows版本是Windows 10 Creators Update之前的版本,则可以尝试使用solution explained in this blog


9
投票

好消息!真正的Linux Docker守护进程在build 17134上运行良好,因此不再需要Windows Docker或Hyper-V。我正在测试Release Preview环上的构建,我只是在WSL内部的linux容器内编译了docker源而没有问题!

只需等待下一周即将发布的下一个Windows 10功能版本!


3
投票

尝试使用WSL运行Linux dockerd守护程序不太可行,Docker for Linux需要运行Linux内核,而WSL是实现Linux系统调用以允许您运行Linux程序的Windows内核。

相反,您应该使用嵌入式Linux VM(Hyper-V或VirtualBox,具体取决于您的版本)安装支持Linux容器的docker for windows。安装Windows版本的docker之后,您将拥有可以从各种命令行访问的docker客户端,包括cmd和bash。


2
投票

在这个时刻,你无法在WSL中运行dockerd和实际的docker运行时。虽然绝不是,但这意味着将来不可能实现。

您仍然可以使用WSL的docker客户端来控制Windows²泊坞窗守护程序及其容器。

在WSL中,只需做一个export DOCKER_HOST='tcp://localhost:2375'。另外,在Windows²Docker设置中允许TCP访问。现在你可以执行docker ps并在Windows²上查看由dockerd驱动的容器。

如果您使用Cannot connect to the Docker daemon at tcp://localhost:2375. Is the docker daemon running?,则表示您未在Windows上的Docker设置中启用TCP访问。

²实际上Windows根本不支持Docker。 Hyper-V“Moby”Linux实例在Windows上启用Docker。


0
投票
  1. 安装"Docker for windows"
  2. "Docker for windows" > settings > general启用expose on tcp//*** without TLS
  3. 在sybsystem上运行以下代码段以安装docker cli
DOCKERVERSION=18.03.1-ce
curl -fsSLO https://download.docker.com/linux/static/stable/x86_64/docker-${DOCKERVERSION}.tgz \
&& tar xzvf docker-${DOCKERVERSION}.tgz --strip 1 -C /usr/local/bin docker/docker \
&& rm docker-${DOCKERVERSION}.tgz
  1. qazxsw药水子系统。
© www.soinside.com 2019 - 2024. All rights reserved.