Docker Windows how to keep container running without login? Docker Windows how to keep container running without login? docker docker

Docker Windows how to keep container running without login?


Since I went through quite a lot of pain in order to make this work, here is a solution that worked for me for running a linux container using docker desktop on a windows 10 VM.

First, read this page to understand a method for running a python script as a windows service.

Then run your container using powershell and give it a name e.g

docker run --name app your_container

In the script you run as a service, e.g the main method of your winservice class, use subprocess.call(['powershell.exe', 'path/to/docker desktop.exe]) to start docker desktop in the service. Then wait for docker to start. I did this by using the docker SDK:

client = docker.from_env()started = Falsewhile not started:    try:        info = client.info()        started = True    except:        time.sleep(1)

When client has started, run your app with subprocess again

subprocess.call(['powershell.exe', 'docker start -interactive app'])

Finally ssh into your container to keep the service and container alive

subprocess.check_call(['powershell.exe', 'docker exec -ti app /bin/bash'])

Now install the service using python service.py install

Now you need to create a service account on the VM that has local admin rights. Go to Services in windows, and find your service in the list of services. Right click -> properties -> Log On and enter the service account details under "This account". Finally, under general, select automatic(delayed) start and start the service.

Probably not the most 'by the book' method, but it worked for me.


what version of docker did you install exactly / in detail?

The procedure to get docker running on a server is very different than for desktops!It's purely script based as described in detail in the MS virtualization docs

The executable name of the windows-server docker EE (enterprise) service is by the way indeed dockerd as in linux.


I've got a better answer from HERE

The summary is to build a Task and assign it to Task Scheduler to run on Windows start.

All the scripts should be run on powershell

  1. Logon to the windows server/machine where you want the Docker services to start automatically.

  2. Create a file called startDocker.ps1 at your location of choice and save the following script inside it:

    start-service -Name com.docker.service

    start C:\'Program Files'\Docker\Docker\'Docker Desktop.exe'

Verify that the location of Docker.exe is correct on your machine otherwise modify it in the script accordingly.

  1. Create a file called registerTask.ps1 and save the following script inside it.

    $trigger = New-ScheduledTaskTrigger -AtStartup

    $action = New-ScheduledTaskAction -Execute "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -Argument "-File C:\PowershellScripts\startDocker.ps1"

    $settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -AllowStartIfOnBatteries

    Register-ScheduledTask -Action $action -Trigger $trigger -TaskName "Start Docker on Start up" -Settings $settings -User "Your user" -Password "Your user password" -RunLevel Highest

This is needed so that this user has access to docker services

try {    Add-LocalGroupMember -Group docker-users -Member "Your user" -ErrorAction Stop} catch [Microsoft.PowerShell.Commands.MemberExistsException] { }
  1. Modify the script: You will have to change a couple of things in the scripts above according to your computer/server.

In the $action line, change the location of startdocker.ps1 script file to where you have placed this file.

In the Register-ScheduledTask line change the account user and password to an account user that needs Docker services to be started at the Windows start-up.

  1. Execute registerTask.ps1

Open Windows Powershell as Administrator and set the current directory to where you have placed registerTask.ps1. For example

cd C:\PewershellScripts\

Next execute this script as follows

.\PowershellScripts\