首页 > 解决方案 > Dockerfile ENTRYPOINT EXEC form not working with Powershell

问题描述

I have to following (simple) Dockerfile:

FROM microsoft/windowsservercore:latest
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
ENTRYPOINT ["Get-ChildItem ", "-Path", "'C:\Program Files\'"]

If I run the container. I get the following error:

At line:1 char:77 + ... ference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; ["Get-Chi ... + ~ Missing type name after '['. At line:1 char:93 + ... $ProgressPreference = 'SilentlyContinue'; ["Get-ChildItem ", "-Path" ... + ~ Missing argument in parameter list. + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordEx ception + FullyQualifiedErrorId : MissingTypename

I also tried:

 ENTRYPOINT ["Get-ChildItem ", "-Path 'C:\Program Files\'"]

and got the same error.

If I use the shell form the ENTRYPOINT in the Dockerfile:

FROM microsoft/windowsservercore:latest
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
ENTRYPOINT Get-ChildItem -Path 'C:\Program Files\'

Everything works fine.

Can somebody tell me how to write this simple PS command in the "exec-form" when using ENTRYPOINT. I'm asking since the docker reference states that the "exec-form" is the preferred one.

Thx

标签: powershelldocker

解决方案


Try removing the trailing space at the end of "Get-ChildItem "

Failing that, is it interpreting \' after Program Files as an escaped character ?


推荐阅读