DockerFile执行PowerShell文件不能find

我试图得到一个使用docker for windows运行的asp.net MVC应用程序。 我已经configuration使用Windows容器。

我正在使用VS2017来添加docker支持,它会生成DockerFile和docker-compose项目。

默认的DockerFile包含:

FROM microsoft/aspnet:4.6.2 ARG source WORKDIR /inetpub/wwwroot COPY ${source:-obj/Docker/publish} . 

创buildconfiguration为使用.net 4.6.2运行IIS的映像

这工作正常,但是我需要configurationSSL。 使用此示例( https://github.com/MicrosoftDocs/Virtualization-Documentation/blob/live/windows-container-samples/iis-https/Dockerfile )并将我的文件更改为:

 FROM microsoft/aspnet:4.6.2 ARG source WORKDIR /inetpub/wwwroot COPY ${source:-obj/Docker/publish} . RUN powershell.exe -Command " \ Import-Module IISAdministration; \ $cert = New-SelfSignedCertificate -DnsName demo.contoso.com -CertStoreLocation cert:\LocalMachine\My; \ $certHash = $cert.GetCertHash(); \ $sm = Get-IISServerManager; \ $sm.Sites[\"Default Web Site\"].Bindings.Add(\"*:443:\", $certHash, \"My\", \"0\"); \ $sm.CommitChanges();" 

工作正常。 然而,这是一个自签名的证书,我希望使用我复制到图像的证书,我也可以将其安装到我自己的机器上的证书存储中,以使其可信。

我已经将DockerFile更改为:

 FROM microsoft/aspnet:4.6.2 ARG source WORKDIR /inetpub/wwwroot COPY ${source:-obj/Docker/publish} . WORKDIR / COPY ${source:-server.pfx} ./server.pfx RUN powershell.exe ls; RUN powershell.exe -executionpolicy bypass -Command " \ Import-Module WebAdministration; \ $pwd = ConvertTo-SecureString -String \"server\" -Force -AsPlainText; \ Import-PfxCertificate -CertStoreLocation \"cert:\\LocalMachine\\Root\\b455d81e2414ec1da38f4de105b98066506cf86e\" -Password $pwd -FilePath \"c:\\server.pfx\"; \ Import-PfxCertificate -CertStoreLocation \"cert:\\LocalMachine\\My\\b455d81e2414ec1da38f4de105b98066506cf86e\" -Password $pwd -FilePath \"c:\\server.pfx\"; \ $cert = Get-Item "cert:\LocalMachine\My\b455d81e2414ec1da38f4de105b98066506cf86e"; \ New-WebBinding -Name \"Default Web Site\" -Protocol \"https\" -IPAddress \"*\" -Port 443; \ New-Item \"IIS:\\SslBindings\\0.0.0.0!443\" -Value $cert;" 

这感觉就像应该工作。 powershell ls命令显示坐在容器c:驱动器上的server.pfx文件。 但是,当它运行powershell命令设置证书错误,说它无法find该文件。

我也遇到了问题,我已经把PowerShell放到一个实际的脚本文件中,将它复制到容器中,执行它,一切都很顺利,但似乎没有任何事情发生。

如果我使用这个chaps docker hub映像,它可以像预期的那样工作,他使用的是一个实际的powershell文件:

https://hub.docker.com/r/rgarita/aspnet-ssl/ https://github.com/rgarita/aspnet-ssl-docker/tree/master/4.6.2

我对此有点不知所措,不确定有没有人有任何想法,或已经经历过类似的痛苦?

提前致谢,

乔恩