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 conn
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>
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 docker -Password (ConvertFrom-SecureString (Read-Host -Prompt 'Password' -AsSecureString) -AsPlainText)
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.
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.