[英]WSL2 Cannot connect to the Docker daemon
here is my setup:这是我的设置:
Windows 10 PRO - build 19041.153
- insider program - slow ring Windows 10 PRO - build 19041.153
- 内部程序 - 慢速环Ubuntu 18.04LTS
subsystem in WSL2 mode Ubuntu 18.04LTS
18.04WSL2模式下的LTS子系统Docker for desktop 2.2.0.4
- enabled WSL2 integration with my Ubuntu subsystem Docker for desktop 2.2.0.4
- 启用 WSL2 与我的 Ubuntu 子系统集成I was currently forced to use Windows for development, so I became microsoft insider member and installed ubuntu with WSL2 mode.我目前被迫使用Windows进行开发,所以我成为了microsoft insider member,用WSL2模式安装了ubuntu。 Docker desktop supports intergration for WSL2, so I tried it... For a week it worked flawlessly.
Docker 桌面支持 WSL2 的集成,所以我尝试了它...... 一个星期它完美无缺。 Today after PC restart, I can't get docker running again.
今天PC重启后,我无法再次运行docker。 Ubuntu can see injected binaries from Docker desktop, but it can't connect to windows hosted docker daemon anymore.
Ubuntu 可以看到从 Docker 桌面注入的二进制文件,但它不能再连接到 windows 托管的 docker 守护进程。
When I call in subsys terminal docker info
it returns当我调用子系统终端
docker info
时,它返回
$ docker info
Client:
Debug Mode: false
Server:
ERROR: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
errors pretty printing info
or with docker-compose up
或
docker-compose up
ERROR: Couldn't connect to Docker daemon at http+docker://localhost - is it running?
If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.
What I've tried already:我已经尝试过的:
DOCKER_HOST=localhost:2375
, DOCKER_HOST=tcp://localhost:2375
, DOCKER_HOST=127.0.0.1:2375
, DOCKER_HOST=tcp://127.0.0.1:2375
=> same resultDOCKER_HOST=localhost:2375
、 DOCKER_HOST=tcp://localhost:2375
、 DOCKER_HOST=127.0.0.1:2375
、 DOCKER_HOST=tcp://127.0.0.1:2375
等 envs 公开守护进程 => 相同的结果I really, really need this to work.我真的,真的需要这个来工作。 Thanks for any ideas.
感谢您的任何想法。 Weirdest thing is it worked yesterday and I didn't make any changes in system from then...
最奇怪的是它昨天工作,从那时起我没有对系统进行任何更改......
I know this may be outdated for present question, but this should save us precious time, especially when Windows 20H1=2004 is going to Production this month (May 2020).我知道这对于目前的问题可能已经过时了,但这应该可以节省我们宝贵的时间,尤其是当 Windows 20H1=2004 将于本月(2020 年 5 月)投入生产时。
Operating System Version : Windows 10 Education (Same as Enterprise and a superset of Pro).操作系统版本:Windows 10 教育版(与企业版相同,是专业版的超集)。
Version : 2004版本:2004
Build (Version OS) : 19041.264构建(版本操作系统) :19041.264
Others : Windows Feature Experience Pack 120.2202.130.0.其他:Windows 功能体验包 120.2202.130.0。
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Shell : WSL Terminal外壳:WSL 终端
First , i have installed WSL v1 previously, then executed procedure for upgrade to WSL v2 , and this error shows up: "ERROR: Cannot connect to the Docker daemon at tcp://localhost:2375. Is the docker daemon running?".首先,我之前已经安装了WSL v1 ,然后执行了升级到WSL v2的过程,并且出现了这个错误:“错误:无法在 tcp://localhost:2375 连接到 Docker 守护进程。docker 守护进程是否正在运行?”。
Second , to fix that, I followed instructions stated here: Link , and it worked.其次,为了解决这个问题,我按照此处所述的说明进行操作: Link ,它起作用了。
Third , after some tests i think the missing change in the upgrade, was remove DOCKER_HOST variable from shell's start script.第三,经过一些测试,我认为升级中缺少的更改是从 shell 的启动脚本中删除 DOCKER_HOST 变量。
SUMMARY: In my case, the procedure for a permanent fix should be following STEPs :摘要:就我而言,永久修复的程序应遵循以下步骤:
1. Test if it's your case unsetting DOCKER_HOST variable (See image below). 1.测试是否是您取消设置 DOCKER_HOST 变量的情况(见下图)。
2. If the error disappears with previous step, then time to fix changes removing setting of DOCKER_HOST variable in the shell's start script (In my case was $HOME/.bashrc ). 2.如果上一步错误消失,那么是时候修复更改了,删除 shell 启动脚本中 DOCKER_HOST 变量的设置(在我的例子中是$HOME/.bashrc )。
Commented this out:对此进行了评论:
#export DOCKER_HOST=tcp://localhost:2375
#export DOCKER_BUILDKIT=1
NOTE : Also include DOCKER_BUILDKIT.注意:还包括 DOCKER_BUILDKIT。
3. Close and open the Terminal. 3.关闭并打开终端。
如果它对遇到此问题的其他人有所帮助,对我来说,事实证明我的子系统突然(并且“自行”)在 docker 的 RESOURCES > WSL INTEGRATION 设置中关闭。
I had installed Docker for Windows, as recommended , to use it with WSL 2 and that does indeed start the docker daemon for you.我已经按照建议安装了 Docker for Windows,以便将它与WSL 2一起使用,这确实为您启动了 docker 守护程序。 But I don't need all the fancy features it offers so removed it and was pleased to see about 4GB freed and no extra icon in the system tray.
但我不需要它提供的所有花哨的功能,所以删除了它,很高兴看到释放了大约 4GB 空间并且系统托盘中没有额外的图标。
Now if I need to run docker commands I just begin with:现在,如果我需要运行 docker 命令,我只需从以下内容开始:
sudo dockerd &
This way I can have it running on the background on the same shell.这样我就可以让它在同一个 shell 的后台运行。 Note that in this example I have setup
sudo
without password.请注意,在此示例中,我设置了没有密码的
sudo
。 If a password is required, I can do sudo dockerd
and open another terminal tab.如果需要密码,我可以执行
sudo dockerd
并打开另一个终端选项卡。
Although this works as a quick temporary solution I've seen it cause network issues so I would not recommend it, and prefer using a light VM instead .虽然这是一个快速的临时解决方案,但我发现它会导致网络问题,所以我不推荐它,而是更喜欢使用轻型 VM 。
在 Docker 桌面应用程序上,我必须手动启用我的发行版集成
Settings > Resources > WSL Integration
I have found my issue was due to mis-reading instructions., fixed on my windows version 1909 and WSL 2 with the following commands on CMD:我发现我的问题是由于错误阅读说明造成的。在我的 Windows 版本 1909 和 WSL 2 上通过 CMD 上的以下命令修复:
wsl.exe -l -v
wsl.exe --set-version ${distro-name} ${wsl version}
example:例子:
C:\Users\xxxxx>wsl.exe -l -v
NAME STATE VERSION
* Ubuntu-18.04 Running 1
docker-desktop-data Running 2
docker-desktop Running 2
C:\Users\xxxxx>wsl.exe --set-version Ubuntu-18.04 2
Conversion in progress, this may take a few minutes...
For information on key differences with WSL 2 please visit https://aka.ms/wsl2
That's it而已
I've tried soooo many things, and the stuff that worked for me, and no one ever mentioned to try:我已经尝试了很多东西,以及对我有用的东西,但没有人提到要尝试:
(from Windows Powershell) (来自 Windows Powershell)
wsl --set-default <my-distro>
then and there, I could connect to docker without changing the DOCKER_HOST
var.然后在那里,我可以在不更改
DOCKER_HOST
的情况下连接到 docker。
ISSUE: Cannot connect to the Docker daemon at tcp://127.0.0.1:2375
ISSUE: 无法在 tcp://127.0.0.1:2375 连接到 Docker 守护程序
wsl -l -v # ALL DISPLAY "2"
unset DOCKER_HOST
/etc/init.d/docker restart
windows docker restart
windows firewall off
docker ps
1.open windows docker desktop --> Setting -->General --> Disable Expose daemon on tcp://localhost:2375 without TLS 1.open windows docker desktop --> Setting -->General --> Disable Expose daemon on tcp://localhost:2375 without TLS
2.and then Go to Settings --> Resources --> WSL integration --> uncheck Enable integration with my default WSL distro and turn off integration with distro 2.然后转到设置->资源-> WSL集成->取消选中启用与我的默认WSL发行版的集成并关闭与发行版的集成
3.click apply and restart 3.点击应用并重启
4.then go to ubuntu try docker ps 4.然后去ubuntu试试docker ps
docker ps
if it does not work, continue to run the following command unset DOCKER_HOST
to disable DOCKER_HOST docker ps
如果不起作用,继续运行以下命令unset DOCKER_HOST
禁用DOCKER_HOST
Today I just tried it successfully今天刚试成功
good luck to you祝你好运
I had the same problem, the solution for me was to set my Ubuntu as the default wsl distribution: wsl --set-default Ubuntu我遇到了同样的问题,我的解决方案是将我的 Ubuntu 设置为默认的 wsl 发行版:wsl --set-default Ubuntu
you can consider upgrading your version to 19582.1000 , it's work for me.您可以考虑将您的版本升级到 19582.1000 ,这对我有用。
See this issue .看到这个问题。
For whatever it's worth (this is an old thread).不管它值多少钱(这是一个旧线程)。 Maybe someone else is still desperately trying to solve this puzzle.
也许其他人仍在拼命试图解决这个难题。
I have just stumbled over the solution in my case.在我的案例中,我刚刚偶然发现了解决方案。 I am running the following
我正在运行以下
My ultimate error were access rights on /var/run/docker.sock, and I am running wsl under my personal user srw-rw---- 1 root docker 0 May 7 10:29 /var/run/docker.sock我的最终错误是对 /var/run/docker.sock 的访问权限,并且我在我的个人用户 srw-rw 下运行 wsl---- 1 root docker 0 May 7 10:29 /var/run/docker.sock
So if I run as root (sudo docker info) or I put myself into group "docker" (sudo usermod -aG docker $USER) I'm all well.因此,如果我以 root 身份运行(sudo docker info)或者我将自己放入组“docker”(sudo usermod -aG docker $USER),我一切都很好。 Please look here https://docs.docker.com/engine/install/linux-postinstall/
请看这里https://docs.docker.com/engine/install/linux-postinstall/
There is another very basic catch:还有另一个非常基本的问题:
After hours, my docker worked using following method.几个小时后,我的码头工人使用以下方法工作。
Go to docker desktop --> Setting -->General --> Disable Expose daemon on tcp://localhost:2375 without TLS转到docker 桌面 --> 设置 --> 常规 --> 在没有 TLS 的情况下禁用 tcp://localhost:2375 上的公开守护进程
Go to Settings --> Resources --> WSL integration --> uncheck Enable integration with my default WSL distro and turn off integration with distro转到设置 --> 资源 --> WSL 集成 --> 取消选中启用与我的默认 WSL 发行版的集成并关闭与发行版的集成
Restart Docker desktop重启 Docker 桌面
Now in WSL,现在在 WSL,
unset DOCKER_HOST
Now try,现在试试,
docker ps
The accepted answer is mostly correct.接受的答案大多是正确的。 However, I wanted to specify that when using WSL2 + Docker Desktop:
但是,我想在使用 WSL2 + Docker Desktop 时指定:
~/.bashrc
in both Windows and WSL.~/.bashrc
中定义。env | grep -i docker
env | grep -i docker
env | grep -i docker
to make sure it's gone. env | grep -i docker
以确保它消失了。Export daemon on tcp://localhost:2375 without TLS
Export daemon on tcp://localhost:2375 without TLS
Use the WSL2 based engine
Use the WSL2 based engine
Enable integration with my default WSL distro
Enable integration with my default WSL distro
Now, you can do a simple docker info
to check if you're running the same server version in WSL and in Windows (Powershell).现在,您可以执行一个简单的
docker info
来检查您是否在 WSL 和 Windows (Powershell) 中运行相同的服务器版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.