Reputation: 761
We have Docker for Windows installed on a Windows Server 2016 Datacenter box.
We use this box as a build agent for our docker containers.
When we try to connect to this box via the daemon to build a container, we get an error message indicating the daemon is not running (at end of post).
However, if I login to this box using my AD Account, the daemon starts, runs, and then I can connect and do everything I need to do.
Is there a way to make daemon start at boot without requiring the user to be logged in? The service only seems to run if a user is logged in.
Error message:
error during connect: Post http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.37/build?buildargs=%7B%7D&cachefrom=%5B%5D&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=[NameRemovedForPrivacy]&labels=%7B%7D&memory=0&memswap=0&networkmode=default&rm=1&session=[keyRemovedForPrivacy]&shmsize=0&t=[serverNameRemovedForPrivacy]&target=&ulimits=null: open //./pipe/docker_engine: The system cannot find the file specified. In the default daemon configuration on Windows, the docker client must be run elevated to connect. This error may also indicate that the docker daemon is not running.
What I have tried:
executable
and com.service.docker
at boot with eleveated
priveleges.Upvotes: 56
Views: 96269
Reputation: 432
For those of you who have tried all of these instructions to no avail, I FINALLY come up with a solution that works for me. My problem was that every time I would log into my computer, I would get a UAC popup. This popup prevented Docker from starting on it's own without login. Here's how to fix that.
You'll want to follow Milad Teimouri's answer, but under "Actions", not only do you want to add "C:\Program Files\Docker\Docker\Docker Desktop.exe"
, you need to add "C:\Program Files\Docker\Docker\resources\com.docker.admin.exe"
as well (make sure it's first!), and in the "Add arguments (optional)" section, you need to enter start-service
.
Here's an image to help:
Upvotes: 0
Reputation: 23
Apparently, in a command prompt, you can change directory to DockerInstallDirectory\Docker\resources and run
C:\DockerInstallDirectory\Docker\resources> dockerd --register-service
Found here: https://www.coretechnologies.com/products/AlwaysUp/Apps/StartDockerDaemonAsAWindowsService.html
I'm not able to test this for the next 10 days as the required computer is unavailable. I'll edit with results when I do.
Upvotes: 2
Reputation: 623
I have tried all methods in this post and they all have flaws. Finally, I use the steps to solve my problem:
Yes, I give up running Docker Desktop when not logged in, I use autologin.
For ref. How to Enable Auto Login on Windows 11? https://www.stellarinfo.com/article/windows-11-auto-login.php
Upvotes: 1
Reputation: 153
I got it working now following these instructions.
The most important steps are to add a task with Task Schedulder with an At Startup
trigger and make it Run whether user is logged in or not
. You can basically follow the steps from the answer by Milad Teimouri. But instead of launching Docker Desktop.exe
directly, make it run a Power Shell script which starts Docker Desktop and the Docker Service, e.g. like this:
start "C:\Program Files\Docker\Docker\Docker Desktop.exe"
start-service -Name com.docker.service
Upvotes: 4
Reputation: 621
Here's a PowerShell script that creates the scheduled task and is verified to work on Windows 10:
$trigger = New-ScheduledTaskTrigger -AtStartup
$trigger.Delay = 'PT1M'
$action = New-ScheduledTaskAction -Execute 'C:\Program Files\Docker\Docker\Docker Desktop.exe'
$settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable -RestartCount 999
$settings.ExecutionTimeLimit = 'PT0S'
$settings.RestartInterval = 'PT1M'
Register-ScheduledTask -Action $action -Trigger $trigger -TaskName Docker -Settings $settings -User $env:UserName -Password (ConvertFrom-SecureString (Read-Host -Prompt 'Password' -AsSecureString) -AsPlainText)
Upvotes: 14
Reputation: 761
Note, none-free software solution, but has 30 days trial version.
I can confirm eckes' comment above. Nothing seems to work. I was very diligent with setting up the Task Scheduler to run under the SYSTEM user with elevated priveleges, etc. and still no luck.
I did find one solution that requires third party software. The software AlwaysUp allows Docker to run at startup without the need to login.
I followed the instructions, except rather than Docker Tools as the executable to run, I pointed to reference\dockerd.exe
. Restarted the server, and sure enough I can now connect to my remote daemon.
I recommend this approach as the simplest solution.
Upvotes: -1
Reputation: 47
In Addition to @Leon V, this was verified to work on windows server 2019, just change username and password:
$trigger = New-ScheduledTaskTrigger -AtStartup
$trigger.Delay = 'PT1M'
$action = New-ScheduledTaskAction -Execute 'C:\Program Files\Docker\dockerd.exe'
$settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable -RestartCount 999
$settings.ExecutionTimeLimit = 'PT0S'
$settings.RestartInterval = 'PT1M'
Register-ScheduledTask -Action $action -Trigger $trigger -TaskName StartDockerAtStartup -Settings $settings -User <username> -Password <password>
Upvotes: 0
Reputation: 1211
The best solution for windows server is to use Task Scheduler
to create task that run "Docker Desktop" app in case of system startup.
to do that search "Task Scheduler", click on "create task...".
on the new tab specify a name for the task and choose "Run whether user is logged on or not" radio button and "Run with highest privilege" checkbox. at the end of page select appropriate windows type.
now click trigger tab and add new trigger. on the new trigger page select "At startup" and click OK.
finally, click on the actions tab and add a new Action that run "Docker windows" shortcut that run docker daemon on windows.
As docker starting, pass 1 minute and container starting may take a few time (in my case 4 minute) wait a few minutes and then test whether your docker is running.
Upvotes: 45