1

Below is my entrypoint.ps1 (PowerShell-script):

Set-Location -Path C:\nginx
& "C:\nginx\Configure-Nginx.ps1"
& "C:\nginx\nginx.exe"

I need to my Configure-Nginx.ps1 and node.exe were executed on docker run so I've put an entrypoint to my Dockerfile:

FROM nginx 
# nginx is a custom image that's based on mcr.microsoft.com/windows/servercore:1809-KB5003171
COPY entrypoint.ps1 ./
COPY install/Configure-Nginx.ps1 /nginx/Configure-Nginx.ps1
ENTRYPOINT ["powershell", "entrypoint.ps1"]

However my container begins to restart each minute... Well, I've decided there is a some error in the script then I run this image manually with --entrypoint powershell and executed my script in the console directly: .\entrypoint.ps1. The script was frozen (cuz nginx was launched) and I could connect to my container from web-browser on the host machine... So everything works! Then why doesn't it work if I call my entrypoint from Dockerfile? What's difference? Maybe someone has met a similar problem...

P.S. The container is based on mcr.microsoft.com/windows/servercore:1809-KB5003171 with PowerShell v5.1.17763.1852

6
  • 1
    Could you please show us the whole Dockerfile? Also you can see logs by docker logs <containerName> maybe that could be helpful. Commented May 25, 2021 at 12:40
  • @YamaçKurtuluş I've provided more details, unfortunately, I can't post a whole Dockerfile. Commented May 25, 2021 at 12:44
  • 1
    That's enough details, Check the workdir of the custom image. It is possible that teh scripts are not being copied over to right locations. By the way, it is not best practice to use the root as default workdir. Commented May 25, 2021 at 12:59
  • 1
    @YamaçKurtuluş, all scripts are in right locations, I've checked already. And as I said it works if I run the script manually from container. Commented May 25, 2021 at 13:01
  • 1
    Did you try docker logs? Maybe add some echo in your scripts to make sure they are being run. Then you can see the output with docker logs or by running in attached mode. At least you can see if that's a problem with script or docker. I am also curious, do you HAVE TO use Windows? If you have the chance, run to Linux I don't have a choice, and I can guarantee this is only the beginning of your problems Commented May 25, 2021 at 13:12

1 Answer 1

2

Firs make sure the script is available under the container root:

COPY entrypoint.ps1 /entrypoint.ps1

Then execute it either by -Command or -File:

ENTRYPOINT ["pwsh", "-Command", "/entrypoint.ps1"]
ENTRYPOINT ["pwsh", "-File","/entrypoint.ps1"]
Sign up to request clarification or add additional context in comments.

6 Comments

Ahh right, the powershell in newer Windows containers is called "pwsh"
Thank you, I gonna try
Unfortunately, it didn't help, I tried to add -File and -Command flags. Also I've specified a version of PowerShell in my question (v5.1.17763.1852) so there should be powershell name.
elaborate: is this script not running at all or it runs and exits prematurely? +1 powershell for v5
I marked yo answer as right cuz it is. Unfortunately, my real mistake was very stupid, I didn't notice that I was watching logs of another similar container and couldn't get why it restarts each one minute. I forgot to change env variable name in my docker-compose.yml but I used right one for manual test that's why everything worked.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.