Docker entrypoints for windows with TERM signal support.
- Install
entrypoint.exeorpsentrypoint.exeinto your .NET Framework container image. - Add an ENTRYPOINT directive to your
dockerfile.
Windows docker entrypoint with Ctrl+C support for cmd.exe based command execution.
Run entrypoint command
ENTRYPOINT [ "entrypoint.exe", "cmd.exe", "/c", "(net start MYSERVICE && ping -t 127.0.0.1) || (echo stopping... && net stop MYSERVICE)"]Run entrypoint command with separate stop command
ENTRYPOINT [ "entrypoint.exe", "cmd.exe", "/c", "net start MYSERVICE && ping -t 127.0.0.1", "--stop", "net stop MYSERVICE"]Windows docker entrypoint with Ctrl+C support for powershell.exe based command execution.
Run entrypoint script and a shutdown script with custom stop timeout.
ENTRYPOINT [ "psentrypoint.exe", "--entrypointScript", "C:\bin\entrypoint\Development.ps1", "--shutdownScript", "C:\bin\entrypoint\Shutdown.ps1", "--stop-timeout", "2000" ]
Run an entrypoint script and use a shutdown command.
ENTRYPOINT [ "psentrypoint.exe", "--entrypointScript", "C:\bin\entrypoint\Development.ps1", "--shutdownCommand", "Stop-Service mysql" ]
Entrypoint.ps1
# startup# run codewhile(!$entrypoint.Shutdown)
{
Write-Verbose-Verbose -Message "Running"Start-Sleep-Seconds 1
}
# shutdownWrite-Host"Shutting down gracefully"Shutdown.ps1
Write-Host"Shutting down"Start-Sleep-Seconds 1Write-Host"Shutdown complete"Dockerfile
ENTRYPOINT [ "psentrypoint.exe", "--entrypointScript", "Entrypoint.ps1", "--shutdownScript", "Shutdown.ps1" ]Entrypoint commands/scripts can use the special $container variable to interact
with psentrypoint.exe.
The $container variable is an IEntrypoint object, provided by psentrypoint.exe, which is added to the PSHost so you can access it's properties and methods from your scripts.
interfaceIEntrypointState{boolShutdown{get;}voidRequestShutdown();voidReportFatalError(Exceptionproblem);}Request container shutdown from within your entrypoint
# start container&C:\bin\entrypoint\scripts\Register-Runner.ps1Start-Service gitlab-runner
Start-Sleep-Seconds 2# run loopwhile (!$entrypoint.Shutdown)
{
Start-Sleep-Milliseconds 500# check if service is running$serviceRunning= (Get-Service gitlab-runner).Status -eq'Running'if (!$serviceRunning)
{
# send shutdown request to psentrypoint.exe$entrypoint.RequestShutdown()
}
}
# stop containerStop-Service gitlab-runner
&C:\bin\entrypoint\scripts\Unregister-Runner.ps1Use a trap to catch exceptions
trap { $entrypoint.ReportFatalError([Exception]::new("$_"))
}
# start container&C:\bin\entrypoint\scripts\Register-Runner.ps1Start-Service gitlab-runner
Start-Sleep-Seconds 2# run loopwhile (!$entrypoint.Shutdown)
{
Start-Sleep-Milliseconds 500# check if service is running$serviceRunning= (Get-Service gitlab-runner).Status -eq'Running'if (!$serviceRunning)
{
# throw an exception to trigger the trapthrow"Service not running"
}
}
# stop containerStop-Service gitlab-runner
&C:\bin\entrypoint\scripts\Unregister-Runner.ps1