简体   繁体   English

"在适用于 Linux 的 Windows 子系统上的 Ubuntu 上运行 Docker"

[英]Run Docker on Ubuntu on Windows Subsystem for Linux

I've tried to run Docker on WSL unsuccessfully.我尝试在 WSL 上运行 Docker 失败。 I've installed Docker on WSL following the steps given to install Docker on Ubuntu<\/a> but when I execute docker ps<\/code> I get the following error:我已经按照在 Ubuntu<\/a>上安装 Docker<\/a>给出的步骤在 WSL 上安装了 Docker,<\/a>但是当我执行docker ps<\/code>出现以下错误:

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

Finally, I could run Docker on WSL in an easy way: You need first to install and run Docker Engine on Windows and then just create a symbolic link on Ubuntu bash pointing to the Windows executable:最后,我可以通过一种简单的方式在 WSL 上运行 Docker:首先需要在 Windows 上安装和运行 Docker 引擎,然后在 Ubuntu bash 上创建一个指向 Windows 可执行文件的符号链接:

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

This link works because from version Windows 10 Creators Update it's possible to run Windows executables from Bash.此链接有效,因为从Windows 10 Creators Update版本开始,可以从 Bash 运行 Windows 可执行文件。 If your Windows version is previous to Windows 10 Creators Update you can try the solution explained in this blog如果您的 Windows 版本早于 Windows 10 创意者更新,您可以尝试此博客中介绍解决方案

Good news!好消息! The real linux Docker daemon runs great on build 17134 thus there won't need for the Windows Docker or Hyper-V anymore.真正的 linux Docker 守护进程在构建 17134 上运行良好,因此不再需要 Windows Docker 或 Hyper-V。 I 'm testing the build on Release Preview ring and I just compiled docker sources inside a linux container inside WSL without problem!我正在测试 Release Preview ring 上的构建,我刚刚在 WSL 内的 linux 容器中编译了 docker 源代码,没有问题!

Just wait for the next Windows 10 feature release which will come for everyone in the next weeks!只需等待下一个 Windows 10 功能发布,它将在接下来的几周内面向所有人发布!

Trying to run the Linux dockerd daemon with WSL is unlikely to work, Docker for Linux needs a Linux kernel to run, while WSL is the Windows kernel that implements Linux syscalls to allow you to run Linux programs.尝试使用 WSL 运行 Linux dockerd 守护进程不太可能成功,Linux 的 Docker 需要一个 Linux 内核才能运行,而 WSL 是实现 Linux 系统调用以允许您运行 Linux 程序的 Windows 内核。

Instead, you should install docker for windows which supports Linux containers using an embedded Linux VM (Hyper-V or VirtualBox depending on your version).相反,您应该使用嵌入式 Linux VM(Hyper-V 或 VirtualBox,具体取决于您的版本)为 Windows安装支持 Linux 容器的 docker。 Once you have installed the Windows version of docker, you'll have the docker client that you can access from various command lines, including cmd and bash.安装 Windows 版本的 docker 后,您将拥有可以从各种命令行访问的 docker 客户端,包括 cmd 和 bash。

The given answer is out of date.给出的答案已过时。 Follow the instructions from the same blog, linked to in the that post: Running Docker containers on Bash on Windows .按照同一博客中的说明进行操作,链接到该帖子: 在 Windows 上的 Bash 上运行 Docker 容器 The solution is still very simple.解决方法还是很简单的。

  • Install docker on Windows在 Windows 上安装 docker
  • Add the following lines into your .bashrc, .zshrc, .whateverrc on your WSL将以下行添加到 WSL 上的 .bashrc、.zshrc、.whateverrc 中
export PATH="/mnt/c/Program\ Files/Docker/Docker/resources/bin:$PATH"
alias docker=docker.exe
alias docker-compose=docker-compose.exe

That's it.就是这样。 It works.它有效。

failed to create NAT chain: iptables failed无法创建 NAT 链:iptables 失败

Try running dockerd service with --iptables=false (consider adding -D for debug).尝试使用--iptables=false运行dockerd服务(考虑添加-D进行调试)。

--iptables Enable addition of iptables rules (default true) --iptables启用添加 iptables 规则(默认为 true)

At this very moment you just cannot run dockerd and the actual docker runtime inside WSL.此时此刻,您无法在 WSL 中运行dockerd和实际的dockerd运行时。 Although by no means, it means that it won't be possible in the future.虽然绝不是,但这意味着将来不可能。

Still you may use the docker client from WSL to control your Windows² docker daemon and its containers.你仍然可以使用docker客户端从WSL来控制你的Windows²码头工人守护程序及其容器。

In WSL, just do an export DOCKER_HOST='tcp://localhost:2375' .在 WSL 中,只需执行export DOCKER_HOST='tcp://localhost:2375' Additionally allow TCP access in your Windows² Docker settings.此外,在您的 Windows² Docker 设置中允许 TCP 访问。 Now you may execute docker ps and see the containers that are powered by dockerd on Windows².现在您可以执行docker ps并在dockerd上查看由dockerd提供支持的容器。

If you Cannot connect to the Docker daemon at tcp://localhost:2375. Is the docker daemon running?如果您Cannot connect to the Docker daemon at tcp://localhost:2375. Is the docker daemon running? Cannot connect to the Docker daemon at tcp://localhost:2375. Is the docker daemon running? , it means that you did not enabled TCP access in your Docker settings on Windows. ,这意味着您没有在 Windows 上的 Docker 设置中启用 TCP 访问。

² actually Windows does not support Docker at all. ² 实际上 Windows 根本不支持 Docker。 A Hyper-V "Moby" Linux instance enables Docker on Windows. Hyper-V“Moby”Linux 实例在 Windows 上启用 Docker。

For Window 10 - Build 1909对于 Window 10 - Build 1909

This worked for me.这对我有用。 Run these commands inside WLS Ubuntu.在 WLS Ubuntu 中运行这些命令。

$ sudo ln -s /mnt/c/Program\ Files/Docker/Docker/resources/bin/docker.exe /usr/bin/docker
$ alias docker='docker.exe'
$ alias docker-compose=docker-compose.exe

Windows doesn't let WSL to use TCP for Docker, so you need to link docker file to the docker.exe in windows. Windows 不允许 WSL 为 Docker 使用 TCP,因此您需要将 docker 文件链接到 Windows 中的 docker.exe。

  1. Install "Docker for windows" .安装"Docker for windows"
  2. "Docker for windows" > settings > general Enable expose on tcp//*** without TLS . "Docker for windows" > settings > general expose on tcp//*** without TLS启用expose on tcp//*** without TLS
  3. Run following snippet on sybsystem to install docker cli在 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. export DOCKER_HOST='tcp://localhost:2375' on sybsystem.在 sybsystem 上export DOCKER_HOST='tcp://localhost:2375'

It seems that whether Docker functions properly on WSL may depend on a number of factors, so the right answer on some systems may not be right for all. Docker 能否在 WSL 上正常运行似乎取决于许多因素,因此某些系统上的正确答案可能并不适合所有人。 For me, I couldn't get it to run properly until I installed WSL2, which requires a Windows 10 build that's currently only available by signing up for the Windows Insider Program (as of May 2020).对我来说,在安装 WSL2 之前,我无法让它正常运行,这需要 Windows 10 版本,目前只能通过注册 Windows Insider Program(截至 2020 年 5 月)获得。 After scouring the web and failing with multiple approaches, I finally came across this article , which had the right answers for me.在搜索网络并使用多种方法失败后,我终于看到了这篇文章,它为我提供了正确的答案。

The two caveats to the article for me were that 1. I had to enable "virtualization" (for running virtual machines) in my bios, and 2. The final command for installing docker-compose didn't seem to work, so I followed this .对我来说,这篇文章的两个警告是 1. 我必须在我的 bios 中启用“虚拟化”(用于运行虚拟机),以及 2. 安装 docker-compose 的最终命令似乎不起作用,所以我遵循这个

*Finally, I should note that Docker Desktop will not run on Windows 10 Home edition, so WSL2 was the only option on my system. *最后,我要注意 Docker 桌面不会在 Windows 10 家庭版上运行,所以 WSL2 是我系统上唯一的选择。

Try this command试试这个命令

sudo docker pull mcr.microsoft.com/mssql/server:2019-latest

Change the version of your mssql server before execute.在执行之前更改 mssql 服务器的版本。

In my case the issue was related to the version of wsl<\/code> .就我而言,问题与wsl<\/code>的版本有关。 I changed it to version 2<\/strong> and reinstalled Ubuntu-20.04 and docker and everything worked fine.我将其更改为版本 2<\/strong>并重新安装了 Ubuntu-20.04 和 docker,一切正常。

wsl --set-default-version 2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在适用于Linux的Windows子系统中运行Docker Engine? - Run Docker Engine in Windows Subsystem for Linux? Windows / Linux Ubuntu子系统Github SSH设置 - Windows/Linux Ubuntu Subsystem Github SSH Setup Windows Linux 子系统:无法连接到 unix:///var/run/docker.sock 上的 Docker 守护进程。 docker 守护进程是否正在运行? - Windows Linux subsystem : Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? 如何在 Windows Linux 子系统中运行 rpc? - How to run rpc in Windows Linux Subsystem? 无法连接到服务器:Linux 的 Windows 子系统中 ubuntu 上的 postgresql - Unable to connect to server: postgresql on ubuntu in windows subsystem for linux windows ubuntu 子系统上的 iconv - iconv on windows ubuntu subsystem 当安装在 docker 和 windows 子系统用于 linux 时,“~”会扩展到哪里? - Where does '~' expand to when mounted in docker with windows subsystem for linux? Flutter 和 Windows Linux 的子系统 - Flutter and Windows Subsystem for Linux Linux登录Windows子系统时如何自动运行命令 - How to auto run commands when log on to Windows Subsystem for Linux 如何在 WSL(适用于 Linux 的 Windows 子系统)上使用 Redis 运行 RediSearch 模块 - How to run RediSearch module with Redis on WSL (Windows Subsystem for Linux)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM