Skip to content

Instantly share code, notes, and snippets.

@sandrock
Created September 30, 2022 11:32
Show Gist options
  • Save sandrock/50ebd23418bbf7fc7d75e1cc06a0cd78 to your computer and use it in GitHub Desktop.
Save sandrock/50ebd23418bbf7fc7d75e1cc06a0cd78 to your computer and use it in GitHub Desktop.
Start Docker at Windows startup

Start Docker at Windows startup

Run

Copy the files from this gist into a directory of your choice.

You may customize the StartDocker.ps1 script to include docker commands.

We are now configuring docker to start when Windows starts using the Windows Task Scheduler.
Open an administrator command prompt in the current folder and type:

cd <main folder>
powershell -file .\RegisterTask.ps1

From now on, docker should start when Windows starts.

Info

Inspired from:

I added this:

  • instructions to run the RegisterScript (as admin)
  • the register script uses the current user (admin)

Published under CC BY-SA.

#
# We are now configuring docker to start when Windows starts using the Windows Task Scheduler.
#
# create a scheduled task...
$trigger = New-ScheduledTaskTrigger -AtStartup
$trigger.Delay = 'PT1M'
$action = New-ScheduledTaskAction -Execute "%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -Argument "-File $PSScriptRoot\startDocker.ps1"
$settings = New-ScheduledTaskSettingsSet -Compatibility Win8 -AllowStartIfOnBatteries -StartWhenAvailable -RestartCount 999
$settings.ExecutionTimeLimit = 'PT0S'
$settings.RestartInterval = 'PT1M'
Register-ScheduledTask -Action $action -Trigger $trigger -TaskName "Start Docker on Start up" -Settings $settings -User $env:UserName
# Add the user to the docker-users user-group...
# This is needed so that this user has access to docker services
try {
Add-LocalGroupMember -Group docker-users -Member $env:UserName -ErrorAction Stop
} catch [Microsoft.PowerShell.Commands.MemberExistsException] {
}
#
# We are starting docker and containers (at windows startup)
#
# start service...
echo "Starting service com.docker.service... "
start-service -Name com.docker.service
echo "Starting docker desktop... "
start "%ProgramFiles%\Docker\Docker\Docker Desktop.exe"
# wait a bit before starting containers...
echo "Waiting... "
Start-Sleep 10
# start containers
echo "Starting containers... "
#docker compose up -d -file <docker-compose.yml>
echo "Done. "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment