Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start Docker daemon (windows service) at startup without the need to log-in?

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.
like image 942
Clayton Rothschild Avatar asked Jul 09 '18 18:07

Clayton Rothschild


People also ask

How do I start Docker daemon as a Windows service?

To start Docker in daemon mode, choose Application > Start "Docker Daemon". The state should transition to "Running" after a few seconds and Docker Daemon should be accessible over the remote bridge. That's it! Next time your computer boots, Docker Daemon will start up immediately, before anyone logs on.

Can I run Docker desktop on Windows without admin privileges?

Docker is insecure by design, if a user can run docker command without admin rights (. i.e. belongs to docker group) this basically means that this user can escape the container and become admin on the host.


3 Answers

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.

like image 129
Milad Teimouri Avatar answered Oct 10 '22 11:10

Milad Teimouri


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)
like image 26
Leon V Avatar answered Oct 10 '22 11:10

Leon V


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
like image 3
Jip Avatar answered Oct 10 '22 13:10

Jip