Use script as entry point and forward docker run command

Hi,

I would like to use a powershell script as entry point for my docker container.
This script should execute something, before executing the command that the user provided via docker run.

My dockerfile looks like this:

COPY ["EntryPoint.ps1", "C:/"]
ENTRYPOINT ["pwsh", "EntryPoint.ps1"]

and the entry point script like this:

& "C:\\Program Files\\Microsoft Visual Studio\\2022\\BuildTools\\Common7\\Tools\\Launch-VsDevShell.ps1" -Arch amd64 -HostArch amd64

$Input = $args -join " "
Invoke-Expression $Input

Here I call a visual studio build tools script, that correctly sets up the shell.

My question concerns the end of the entry point script. Is this an appropriate way to execute the forwarded command or is there something better suited? I have the feeling that this solution will break easily. I would also be interested in a solution that doesn’t need to forward the command to the script, but manages everything in the dockerfile.

Thanks and best regards
oz

Most of us here are using Linux containers where we use the exec command to execute the argument of the entrypoint (the command). You can try to search for Powershell alternatives, but if Ir emember correctly, Windows doesn’t handle signals the way Linux does, so maybe there is no alternative. I also don’t remember what the & character does at the beginning of the command in the first line of our script, but I saw using Start-Process instead, which can take the argument list without converting it into a string first, so maybe it can also be used as the last line.

Microsoft mentions it too in the RUN instruction:

https://learn.microsoft.com/en-us/virtualization/windowscontainers/manage-docker/manage-windows-dockerfile#examples-of-using-run-with-windows

Since this is basically a Powershell question, if my sugestions don’t help and you don’t find Windows container users here who wrote their own entrypoint script, you can try Microsoft’s forum where there are probably more Windows container users.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.