Parse Process environment variables to Windows Task

I just got started with Docker on Windows and I have a rather interesting challenge.

I have a service that is built into the Docker Image that can only read Machine level Environment variables, so the objective is to parse env from Docker (or K8s spec) at runtime, then convert the Process Environment variables into Machine Environment variables. This problem is nicely summed up in this Elton’s blog post.

Now, when I use the Powershell bootstrap script to copy the Process Environment variables to Machine environment variables as the ENTRYPOINT command, it all works great.

ENTRYPOINT ["powershell", "./bootstrap.ps1"]

However, an EXE must be used as the ENTRYPOINT of the container according to the specification, so I decided to create a task to run the bootstrap.ps1 script at Startup.

RUN $action = New-ScheduledTaskAction -Execute 'C:\BootstrapInit.bat""'; \
    $trigger = New-ScheduledTaskTrigger -AtStartup ; \
    $principal = New-ScheduledTaskPrincipal -UserID "SYSTEM" ; \
    $settings = New-ScheduledTaskSettingsSet -MultipleInstances Parallel; \
    Register-ScheduledTask -TaskName 'BootstrapMyApp' -Action $action -Trigger $trigger -Description 'blba' -Settings $settings -Principal $principal; 

the batch file calls the Powershell like so:

Powershell.exe -ExecutionPolicy ByPass -File C:\boostrap.ps1 

The Problem:

The script runs successfully, but it’s unable to find the Process Environment variables that were set at runtime. This is most likely due to how Powershell manages environment variables in the session.

The Question:

Is there a way to reload the Process level environment variables that were set during the container startup so as to make them available to the ScheduledTask?