1
+ <#
2
+ . SYNOPSIS
3
+ Starts the container.
4
+ . DESCRIPTION
5
+ Starts a container.
6
+
7
+ This script should be called from the Dockerfile as the ENTRYPOINT (or from within the ENTRYPOINT).
8
+
9
+ It should be deployed to the root of the container image.
10
+
11
+ ~~~Dockerfile
12
+ # Thank you Microsoft! Thank you PowerShell! Thank you Docker!
13
+ FROM mcr.microsoft.com/powershell
14
+ # Set the shell to PowerShell (thanks again, Docker!)
15
+ SHELL ["/bin/pwsh", "-nologo", "-command"]
16
+ # Run the initialization script. This will do all remaining initialization in a single layer.
17
+ RUN --mount=type=bind,src=./,target=/Initialize ./Initialize/Container.init.ps1
18
+
19
+ ENTRYPOINT ["pwsh", "-nologo", "-file", "/Container.start.ps1"]
20
+ ~~~
21
+ . NOTES
22
+ Did you know that in PowerShell you can 'use' namespaces that do not really exist?
23
+ This seems like a nice way to describe a relationship to a container image.
24
+ That is why this file is using the namespace 'mcr.microsoft.com/powershell'.
25
+ (this does nothing, but most likely will be used in the future)
26
+ #>
27
+ using namespace ' ghcr.io/powershellweb/gql'
28
+
29
+ param ()
30
+
31
+ $env: IN_CONTAINER = $true
32
+ $PSStyle.OutputRendering = ' Ansi'
33
+
34
+ $mountedFolders = @ (if (Test-Path ' /proc/mounts' ) {
35
+ (Select-String " \S+\s(?<p>\S+).+rw?,.+symlinkroot=/mnt/host" " /proc/mounts" ).Matches.Groups |
36
+ Where-Object Name -eq p |
37
+ Get-Item - path { $_.Value }
38
+ })
39
+
40
+ if ($mountedFolders ) {
41
+ " Mounted $ ( $mountedFolders.Length ) folders:" | Out-Host
42
+ $mountedFolders | Out-Host
43
+ }
44
+
45
+ if ($args ) {
46
+ # If there are arguments, output them (you could handle them in a more complex way).
47
+ " $args " | Out-Host
48
+ $global :ContainerStartArguments = @ () + $args
49
+
50
+ # region Custom
51
+
52
+ # endregion Custom
53
+ } else {
54
+ # If there are no arguments, see if there is a Microservice.ps1
55
+ if (Test-Path ' ./Microservice.ps1' ) {
56
+ # If there is a Microservice.ps1, run it.
57
+ . ./ Microservice.ps1
58
+ }
59
+ # region Custom
60
+
61
+ # endregion Custom
62
+ }
63
+
64
+ # If you want to do something when the container is stopped, you can register an event.
65
+ # This can call a script that does some cleanup, or sends a message as the service is exiting.
66
+ Register-EngineEvent - SourceIdentifier PowerShell.Exiting - Action {
67
+ if (Test-Path ' /Container.stop.ps1' ) {
68
+ & / Container.stop.ps1
69
+ }
70
+ } | Out-Null
0 commit comments