如果将主机添加到 daemon.json,Windows Docker 守护进程会崩溃 [英] Windows Docker deamon crashes if hosts is added to the daemon.json

查看:34
本文介绍了如果将主机添加到 daemon.json,Windows Docker 守护进程会崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次使用 docker.请注意,我在带有 WSL 2 的 Windows 上使用 Docker 桌面.

This is my first time working with docker. Please take note that I am using Docker Desktop on windows with WSL 2.

我正在使用需要连接到 docker 守护程序以启动新容器的遗留软件的和平.这个软件的设置说明说我需要设置DOCKER_OPTS='-H tcp://127.0.0.1:4243 -H unix:///var/run/docker.sock'.截至目前,我还没有找到在 Windows 中设置 DOCKER_OPTS 的方法,但将其添加到主机应该可以.

I am working with a peace of legacy software that needs to connect to the docker daemon to spin up new containers. The setup instruction for this software say I need to set DOCKER_OPTS='-H tcp://127.0.0.1:4243 -H unix:///var/run/docker.sock'. As of right now I havent found a way to set DOCKER_OPTS in windows, but adding it to the hosts should work.

我遇到的问题是当我尝试将主机添加到 C:\Users\<User>\.docker\daemon.json 文件(或通过 ui)docker无法启动.我在 hosts 对象中添加什么并不重要,只是 hosts 对象会导致 docker 在启动时崩溃.

The issue that I'm having is when I try to add hosts to the C:\Users\<User>\.docker\daemon.json file (or through the ui) docker fails to start. It doesn't matter what I add into the hosts object, just the hosts object causes docker to crash on startup.

据我所知,这似乎是一个已知问题,但我能找到的所有解决方案似乎都没有答案,或者适用于 Linux 而不是 Windows.

From what I understand it looks like this is a known issue, however all solutions that I can found seem unanswered or for Linux and not windows.

我试过使用 -H 命令,看起来命令没有任何变化.

I have tried using the -H command, It doesn't look like anything changes with the command.

如何将主机添加到 daemon.json 文件而不会导致 docker 崩溃,或者至少设置 DOCKER_OPTS 值?

How can I add hosts to the daemon.json file without docker crashing or, at the least, set the DOCKER_OPTS value?

我在:Docker 版本 19.03.8,构建 afacb8bWindows 内部版本 19041.329WSL 2

I am on: Docker version 19.03.8, build afacb8b Windows Build 19041.329 WSL 2

我已经浏览了这些.

DOCKER_OPTS 在配置文件中不起作用/etc/default/docker

在守护进程中配置主机后无法启动docker.json

启用远程 Docker APIWindows 主机 - 添加 daemon.json 会破坏 docker

更改主机"/-h"daemon.json 中的 Docker for Windows

docker 堆栈跟踪:

docker stack trace:

Docker.Core.DockerException:
Failed to start
   at Docker.LinuxkitDaemonStartup.<StartAsync>d__5.MoveNext() in C:\workspaces\stable-2.3.x\src\github.com\docker\pinata\win\src\Docker.Desktop\LinuxkitDaemonStartup.cs:line 59
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Docker.Engines.WSL2.LinuxWSL2Engine.<DoStartAsync>d__23.MoveNext() in C:\workspaces\stable-2.3.x\src\github.com\docker\pinata\win\src\Docker.Desktop\Engines\WSL2\LinuxWSL2Engine.cs:line 149
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Docker.ApiServices.StateMachines.TaskExtensions.<WrapAsyncInCancellationException>d__0.MoveNext() in C:\workspaces\stable-2.3.x\src\github.com\docker\pinata\win\src\Docker.ApiServices\StateMachines\TaskExtensions.cs:line 29
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Docker.ApiServices.StateMachines.StartTransition.<DoRunAsync>d__5.MoveNext() in C:\workspaces\stable-2.3.x\src\github.com\docker\pinata\win\src\Docker.ApiServices\StateMachines\StartTransition.cs:line 67
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Docker.ApiServices.StateMachines.StartTransition.<DoRunAsync>d__5.MoveNext() in C:\workspaces\stable-2.3.x\src\github.com\docker\pinata\win\src\Docker.ApiServices\StateMachines\StartTransition.cs:line 92
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Docker.ApiServices.StateMachines.EngineStateMachine.<StartAsync>d__14.MoveNext() in C:\workspaces\stable-2.3.x\src\github.com\docker\pinata\win\src\Docker.ApiServices\StateMachines\EngineStateMachine.cs:line 72
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Docker.Engines.Engines.<RestartAsync>d__29.MoveNext() in C:\workspaces\stable-2.3.x\src\github.com\docker\pinata\win\src\Docker.Desktop\Engines\Engines.cs:line 274

看起来 docker 的默认行为是在启动时将主机标志设置为默认值.如果您在配置文件中设置主机对象,Docker 将崩溃,因为在您尝试设置已存在的内容时会发生对象冲突.我不知道为什么 docker 会这样做,但是是的,docker 正在按预期工作,但根本没有工作.

It looks like the default behavior of docker is to have the host flag set on startup to a default value. Docker will crash if you set the hosts object in the config file because is will have an object conflict where you trying to set something that already exists. I have no idea why docker did it this way but ya, docker is working as intended, not working at all.

我使用的解决方案是 linux,没错,不要使用 windows,因为无法设置主机对象.在 linux 中,您可以在启动时清除启动配置,然后毫无问题地设置主机对象.

The solution that I used was linux, yes that's right, don't use windows as there is no way to set the hosts object. In linux you can clear the startup config on launch and then set the hosts object without issue.

推荐答案

我也遇到了这个问题.我目前的解决方法是转发到 docker 之外的端口.我在管理员命令提示符下运行此命令:

I'm also experiencing this issue. My current workaround is to forward to the port outside of docker. I run this command in an admin command prompt:

netsh interface portproxy add v4tov4 listenport=2375 listenaddress=192.168.1.20 connectport=2375 connectaddress=127.0.0.1

它甚至在重新启动后仍然存在,您可以通过以下方式进行检查:

It even sticks around after restarts which you can check by:

netsh interface portproxy show all

虽然这不能解决 docker 在编辑主机文件时崩溃的问题,但它允许您将守护程序主机代理到不同的端口.

While this doesn't fix that docker crashes on editing the host file, it will allow you to proxy the daemon host to a different port.

这篇关于如果将主机添加到 daemon.json,Windows Docker 守护进程会崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆