This is my first time working with docker. Please take note that I am using Docker Desktop on windows with WSL 2.
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.
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.
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.
I have tried using the -H command, It doesn't look like anything changes with the command.
How can I add hosts to the daemon.json file without docker crashing or, at the least, set the DOCKER_OPTS value?
I am on: Docker version 19.03.8, build afacb8b Windows Build 19041.329 WSL 2
I have looked through these.
DOCKER_OPTS do not work in config file /etc/default/docker
Unable to start docker after configuring hosts in daemon.json
Enable Remote Docker API on Windows Host - Adding daemon.json breaks docker
Change "hosts" / "-h" Docker for Windows in daemon.json
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
Edit: 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.
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.