无法找到执行powershell文件的DockerFile

时间:2017-08-23 09:50:08

标签: docker docker-compose dockerfile

我试图使用docker for windows运行asp.net MVC应用程序。我已配置为使用Windows容器。

我使用VS2017添加docker支持,生成DockerFile和docker-compose项目。

默认的DockerFile包含:

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

创建配置为使用.net 4.6.2

运行IIS的映像

这很好用,但我需要配置SSL。使用此示例(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命令设置证书时,它会错误地说它无法找到该文件。

我还遇到了一些问题,我将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

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

提前致谢,

乔恩

0 个答案:

没有答案