Skip to content

Commit ee47c9f

Browse files
feat: EZOut Container.start.ps1 ( Fixes #243 )
1 parent 6057944 commit ee47c9f

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

Container.start.ps1

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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/startautomating/rocker'
28+
29+
param()
30+
31+
if ($args) {
32+
# If there are arguments, output them (you could handle them in a more complex way).
33+
"$args" | Out-Host
34+
}
35+
36+
# If you want to do something when the container is stopped, you can register an event.
37+
# This can call a script that does some cleanup, or sends a message as the service is exiting.
38+
Register-EngineEvent -SourceIdentifier PowerShell.Exiting -Action {
39+
if (Test-Path /Container.stop.ps1) {
40+
& /Container.stop.ps1
41+
}
42+
} | Out-Null

Dockerfile

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@ FROM mcr.microsoft.com/powershell
55
SHELL ["/bin/pwsh", "-nologo", "-command"]
66

77
# Run the initialization script
8-
RUN --mount=type=bind,src=./,target=/Initialize ./Initialize/Container.init.ps1
8+
RUN --mount=type=bind,src=./,target=/Initialize ./Initialize/Container.init.ps1
9+
10+
# Set the entry point
11+
ENTRYPOINT ["/bin/pwsh", "-nologo", "-noexit", "-file", "/Container.start.ps1"]

0 commit comments

Comments
 (0)