Skip to content

Repository files navigation

DOCKER ENTRYPOINTS

Docker entrypoints for windows with TERM signal support.

Usage

  • Install entrypoint.exe or psentrypoint.exe into your .NET Framework container image.
  • Add an ENTRYPOINT directive to your dockerfile.

entrypoint.exe

Windows docker entrypoint with Ctrl+C support for cmd.exe based command execution.

Usage Examples

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"]

psentrypoint.exe

Windows docker entrypoint with Ctrl+C support for powershell.exe based command execution.

Usage Example

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" ]

Full Example

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" ]

OutputSample Output

Special Features

Interact with psentrypoint.exe from your scripts

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);}

Usage examples

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.ps1

Use 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

About

Docker entrypoints for windows

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages