无法在 Ubuntu Windows 上的 bash 上连接到 Docker 守护程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48047810/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot connect to the Docker daemon on bash on Ubuntu windows
提问by zsbappa
I am able to install docker, docker-compose and docker-machine
我能够安装 docker、docker-compose 和 docker-machine
However when I try to run
但是,当我尝试运行时
root@DESKTOP-51NFMIM:~# docker ps
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Is there any suggestion for solving this problem?
有没有解决这个问题的建议?
回答by Rami Sarieddine
Found the solution on this post: https://blog.jayway.com/2017/04/19/running-docker-on-bash-on-windows/
在这篇文章中找到了解决方案:https: //blog.jayway.com/2017/04/19/running-docker-on-bash-on-windows/
Running docker against an engine on a different machine is actually quite easy, as Docker can expose a TCP endpoint which the CLI can attach to.
针对不同机器上的引擎运行 docker 实际上非常简单,因为 Docker 可以公开 CLI 可以附加到的 TCP 端点。
This TCP endpoint is turned off by default; to activate it, right-click the Docker icon in your taskbar and choose Settings, and tick the box next to “Expose daemon on tcp://localhost:2375 without TLS”.
这个 TCP 端点默认是关闭的;要激活它,请右键单击任务栏中的 Docker 图标并选择“设置”,然后勾选“在没有 TLS 的情况下在 tcp://localhost:2375 上公开守护程序”旁边的框。
With that done, all we need to do is instruct the CLI under Bash to connect to the engine running under Windows instead of to the non-existing engine running under Bash, like this:
完成后,我们需要做的就是指示 Bash 下的 CLI 连接到在 Windows 下运行的引擎,而不是连接到在 Bash 下运行的不存在的引擎,如下所示:
$ docker -H tcp://0.0.0.0:2375 images
There are two ways to make this permanent – either add an alias for the above command or export an environment variable which instructs Docker where to find the host engine (NOTE: make sure to use single apostrophe's below):
有两种方法可以使其永久化 - 为上述命令添加别名或导出一个环境变量,该变量指示 Docker 在哪里找到主机引擎(注意:确保使用下面的单个撇号):
$ echo "export DOCKER_HOST='tcp://0.0.0.0:2375'" >> ~/.bashrc
$ source ~/.bashrc
Now, running docker commands from Bash works just like they're supposed to.
现在,从 Bash 运行 docker 命令就像他们应该的那样工作。
$ docker run hello-world
Successful response:
成功回复:
Hello from Docker!This message shows that your installation appears to be working correctly.
回答by Stephan
The Docker client and server can now be installed and run purely in WSL without Docker Desktop for Windows if you are running Windows 10 version 1803 or greater. I have it working on the following WSL:
如果您运行的是 Windows 10 版本 1803 或更高版本,Docker 客户端和服务器现在可以完全在 WSL 中安装和运行,无需 Docker Desktop for Windows。我有它在以下 WSL 上工作:
OS: Ubuntu 18.04 bionic [Ubuntu on Windows 10]
Kernel: x86_64 Linux 4.4.0-17763-Microsoft
Simply follow the same instructionsto install on Ubuntu but make sure to choose a specific version to install. Presently, version 18.06.1~ce~3-0~ubuntuworks fine but later versions up to 5:18.09.6~3-0~ubuntu-bionichave an issue with starting up a container. The following command will install the latest working version:
只需按照相同的说明在 Ubuntu 上安装,但请确保选择要安装的特定版本。目前,版本18.06.1~ce~3-0~ubuntu工作正常,但更高版本5:18.09.6~3-0~ubuntu-bionic在启动容器时存在问题。以下命令将安装最新的工作版本:
apt-get install docker-ce=18.06.1~ce~3-0~ubuntu
To get the Docker server running in WSL after installation, close all open terminals and start a new Ubuntu terminal as administrator (i.e., right click the Ubuntu shortcut and click 'Run as administrator'). Finally, run the following commands:
要在安装后让 Docker 服务器在 WSL 中运行,请关闭所有打开的终端并以管理员身份启动一个新的 Ubuntu 终端(即,右键单击 Ubuntu 快捷方式并单击“以管理员身份运行”)。最后,运行以下命令:
sudo cgroupfs-mount
sudo service docker start
sudo service docker start
will have to be run each time Windows is rebooted. However, if you wish to avoid that, you can automate it using the Task Scheduler and a shell script by following the steps listed here.
sudo service docker start
每次重新启动 Windows 时都必须运行。但是,如果您希望避免这种情况,您可以按照此处列出的步骤使用任务计划程序和 shell 脚本自动执行。
Test that everything is working using:
使用以下命令测试一切是否正常:
docker run hello-world
Reference: https://medium.com/faun/docker-running-seamlessly-in-windows-subsystem-linux-6ef8412377aa
参考:https: //medium.com/faun/docker-running-seamless-in-windows-subsystem-linux-6ef8412377aa
回答by VonC
Note: if you are using the Ubuntu from WSL (Windows Subsystem for Linux), do understand that the docker client is working, not the docker server (daemon).
注意:如果您使用的是来自WSL(Linux 的 Windows 子系统)的 Ubuntu,请务必了解 docker 客户端正在运行,而不是 docker 服务器(守护进程)。
See Microsoft/WSL issue 2114and this thread.
For the server, you would still need to use only Docker for Windowsand its Hyper-V VM.
对于服务器,您仍然只需要使用Docker for Windows及其 Hyper-V VM。
Then, Microsoft/WSL issue 2102adds:
然后,Microsoft/WSL 问题 2102补充说:
I was able to make TLS work from inside WSL by changing
DOCKER_CERT_PATH
environment variable (which I got from runningeval $(docker-machine.exe env --shell bash)
) from "C:\C:\Users\mmarchini\.docker\machine\machines\default
" to "/mnt/c/Users/mmarchini/.docker/machine/machines/default/
" .
At least docker build seems to be working now, I'll try usingdocker-compose
later.
通过将
DOCKER_CERT_PATH
环境变量(我从运行中获得的eval $(docker-machine.exe env --shell bash)
)从“C:\C:\Users\mmarchini\.docker\machine\machines\default
”更改为“/mnt/c/Users/mmarchini/.docker/machine/machines/default/
” ,我能够从 WSL 内部使 TLS 工作。
至少 docker build 现在似乎可以工作了,我稍后会尝试使用docker-compose
。
See this script(from Matheus Marchini) to launch a docker-machine bash with the right setting:
请参阅此脚本(来自Matheus Marchini)以启动具有正确设置的 docker-machine bash:
#!/usr/bin/env python3
from subprocess import run, PIPE
completed_process = run(["docker-machine.exe", "env", "--shell", "bash"], stdout=PIPE)
docker_env = completed_process.stdout.decode("ascii")
for line in docker_env.split("\n"):
if "DOCKER_CERT_PATH" in line:
env_var, path, _ = line.split('"')
path = path.replace("\", "/")
drive, path = path.split(":", 1)
path = "/mnt/{}{}".format(drive.lower(), path)
line = '{}"{}"'.format(env_var, path)
print(line)
回答by Md. Tazbir Ur Rahman Bhuiyan
for me this worked for WSL for windows:
对我来说,这适用于 Windows 的 WSL:
- 1> go to: Turn Windows features on or off
- 2> deselect "Hyper-V", restart,
- 3> go to "Turn Windows features on or off" again,
- 4> select "Hyper-V" again
- and restart a last time. Afterwards docker was reachable again.
- 1>转到:打开或关闭Windows功能
- 2> 取消选择“Hyper-V”,重新启动,
- 3> 再次转到“打开或关闭 Windows 功能”,
- 4> 再次选择“Hyper-V”
- 并重新启动最后一次。之后 docker 又可以访问了。
assuming you have installed docker desktop for windows and Settings->General->Expose daemon on tcp://localhost:2375 without TLS is ticked
假设您已经为 Windows 安装了 docker 桌面,并且在没有 TLS 的情况下勾选了 tcp://localhost:2375 上的 Settings->General->Expose daemon
回答by rob2universe
If you are using docker desktop for windows (and do not require TLS for the connection) then go to the docker desktop setting, general section and enabled the checkbox "Expose daemon on tcp://localhost:2375 without TLS".
如果您在 Windows 上使用 docker 桌面(并且不需要 TLS 进行连接),请转到 docker 桌面设置,常规部分并启用复选框“在没有 TLS 的情况下在 tcp://localhost:2375 上公开守护程序”。