How to manually start IIS in image iis:windowsservercore-ltsc2019?

The windows image iis:windowsservercore-ltsc2019 starts IIS manually. I need to execute a command after the docker build but prior to starting IIS. The objective is to replace compiled node .env data with docker .env data at run time similar to this Alpine image example: GitHub - juanise/jvjr-docker-env-example. Unfortunately my work would like to continue using Windows images.

The docker file:

FROM mcr.microsoft.com/windows/servercore/iis:windowsservercore-ltsc2019 as build-stage
EXPOSE 80

# install nodejs
SHELL ["cmd", "/S", "/C"]
ADD ./DockerBuildAssets/node-v16.12.0-x64.msi nodejs.msi
RUN msiexec.exe /q /i nodejs.msi
RUN del /f nodejs.msi

WORKDIR /app

COPY package*json ./

COPY .env .
RUN npm install
COPY . .
RUN npm run build

COPY jvjr-env.json /
COPY start.bat /
COPY ./DockerBuildAssets/jvjr-entrypoint.ps1 /

# Copy output to IIS
RUN xcopy .\build c:\inetpub\wwwroot /E /Q /Y

# this appears to replace / override IIS start.
CMD C:\start.bat

Start.bat:

echo “starting up”
REM variable replace here.
start c:\ServiceMonitor.exe w3svc
echo “finished starting up”

Docker run results in:

Service 'w3svc' has been stopped

APPCMD failed with error code 4312

Failed to update IIS configuration

Even with the variable replace function commented out, IIS crashes. Any ideas what is going on here / how to start IIS manually after another command?

Thanks

I found the same error message from years ago

https://stackoverflow.com/questions/58186260/iis-dockerfile-appcmd-failed-with-error-code-4312

I have not used this image, but if it has an entrypoint as the answer indicates, you need to check that too. But another post refers to this issue on GitHub, where someone wrote a solution worked:

Thanks for the response. In case this helps anyone else:

Dockerfile:

#this replaces the IIS entry point
ENTRYPOINT ["powershell.exe", "C:\\entrypoint.ps1", "c:\\inetpub\\wwwroot\\static\\js", "main" ]

Powershell:

// Do variable transformations here,
Write-Output "Starting ServiceMonitor.exe"
C:\\ServiceMonitor.exe w3svc

This does not appear to work with a batch file but does work with a powershell. No idea why.