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.
Clayton Rothschild
  • 702
  • 1
  • 5
  • 15
  • 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 09 '18 at 19:00
  • Here is a complete post on how to achieve this https://thecodeframework.com/start-docker-desktop-on-windows-start-up-without-user-logon/ – Gagan Aug 02 '20 at 02:50

8 Answers8

40

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.

Milad Teimouri
  • 1,141
  • 9
  • 17
  • 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. – Milad Teimouri Dec 25 '19 at 05:33
  • I can confirm this works for me. My build server is running windows 10, WCOW. Here were the gotchas I faced: We use a different domain account to run jobs on our buildserver. That account had to be added to the docker users group. Before doing so docker desktop would start but the daemon service would not. I also had to log in as that user and configure docker to use windows containers for that user. – Nick Jun 26 '20 at 16:52
  • This worked for us on Windows 10, but it required us to make the account that starts Docker Desktop an administrator on the machine. – Anders Ekdahl Nov 20 '20 at 13:57
  • 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 01 '20 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. – Larry Silverman May 03 '21 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 07 '21 at 09: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 '22 at 16:50
13

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)
Leon V
  • 541
  • 5
  • 12
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
Jip
  • 123
  • 8
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>
tal47
  • 37
  • 4
  • Is there any differences between yours and eon V's solution? Better pointing that out if so. – xpt Feb 11 '21 at 22:08
0

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

0

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

eric xu
  • 523
  • 5
  • 13
-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.

xpt
  • 20,363
  • 37
  • 127
  • 216
Clayton Rothschild
  • 702
  • 1
  • 5
  • 15
  • 9
    Worth mentioning that AlwaysUp is not free but has 30 days trial version – mmahgoub Mar 13 '19 at 12:01
  • 1
    Update December 2020: I am changing my accepted answer from this answer to the answer by Milad Teimouri (https://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. – Clayton Rothschild Dec 11 '20 at 17:46
  • $50 for always up? Whoa! – KevinB Jul 08 '22 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.

helvete
  • 2,455
  • 13
  • 33
  • 37