51

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:

  • Verified Docker was listed in Windows Services and configured to start automatically.
  • Created entries in Windows Task Scheduler to execute docker executable and com.service.docker at boot with eleveated priveleges.
2
  • 2
    I had this requirement one year ago and found no way to run docker as a service on Windows without having to log in. Ended up with creating a Debian VM being run as Hyper-V-machine. This is run as a service and is the host for Docker.
    – eckes
    Jul 9, 2018 at 19:00
  • Here is a complete post on how to achieve this thecodeframework.com/…
    – Gagan
    Aug 2, 2020 at 2:50

8 Answers 8

41

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.

Create Task

now click trigger tab and add new trigger. on the new trigger page select "At startup" and click OK.

enter image description here

finally, click on the actions tab and add a new Action that run "Docker windows" shortcut that run docker daemon on windows.

Create Action

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.

7
  • yes i test it, but i forgot to mention set 1 minute delay in creating trigger. in creating trigger step, set 1 minute delay in front of "Delay task for:" label and test it again. as starting docker, pass 1 minute and starting container may take some minutes (in my case 4 minute) wait for some minutes and then test if your docker is running. Dec 25, 2019 at 5:33
  • 2
    Guys, I tried this solution, but even if it solves the problem I observed that Docker tray icon disappears and I can't open the dashboard anymore after having set it as service... Has anyone encountered this behaviour?
    – DDD
    Dec 1, 2020 at 15:29
  • 1
    This method worked for me for a couple of years, but recently began failing. The Docker for Windows folks seem to have added some Toast notifications for this and that, and when there is no user logged in, those attempted toast calls seem to prevent the invocation of my container. I can find no option to disable toast notifications. May 3, 2021 at 19:06
  • 1
    @LarrySilverman Regarding toast notifications. update /c/Users/.../AppData/Roaming/Docker/settings.json with values that suppress them, e.g. "disableTips": true, "displayed18362Deprecation": true, "openUIOnStartupDisabled": true.
    – hlovdal
    Oct 7, 2021 at 9:56
  • 7
    Unfortunately not working for me on Windows Server 2019 with the latest Docker. In Task Manager I can see that Docker Desktop and all its related processes (and the com.docker.service) are running on startup. However, none of the containers run. Running docker container ls in Administrator command prompt gives error during connect: In the deafult daemon configuration on Windows, the docker client must be run with elevated priviliges to connect.
    – Jip
    Jan 12, 2022 at 16:50
14

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)
3
  • Thank you - this worked. I just had to replace the user in the last command with my own. Aug 31, 2020 at 18:33
  • 1
    To replace the user in the last command with me, replace -User docker with -User $env:UserName
    – xpt
    Feb 11, 2021 at 22:14
  • 1
    This answer only applied for PowerShell 7+.
    – Will Huang
    Oct 13, 2022 at 15:17
3

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
1

I have tried all methods in this post and they all have flaws. Finally, I use the steps to solve my problem:

  1. Set automatic login after startup
  2. Docker Desktop settings check "Start Docker Desktop when you log in"
  3. Docker Desktop settings uncheck "Open Docker Dashboard at startup"

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

0

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>
1
  • Is there any differences between yours and eon V's solution? Better pointing that out if so.
    – xpt
    Feb 11, 2021 at 22:08
0

If this problem comes in Windows 10, just try to restart the Docker service.

-1

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.

3
  • 9
    Worth mentioning that AlwaysUp is not free but has 30 days trial version
    – mmahgoub
    Mar 13, 2019 at 12:01
  • 1
    Update December 2020: I am changing my accepted answer from this answer to the answer by Milad Teimouri (stackoverflow.com/a/59467740/7547525). The approach here still works, however it appears the same can be accomplished without the use of 3rd-party tools. Dec 11, 2020 at 17:46
  • $50 for always up? Whoa!
    – KevinB
    Jul 8, 2022 at 21:28
-1

Docker Settings

Now you can check Start Docker Desktop when you log in option at docker settings, then apply and restart.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.