我可以在Docker构建期间将MVC 3安装到Windows容器中吗?

时间:2018-06-05 22:10:31

标签: docker asp.net-mvc-3 dockerfile windows-container

我正试图"提升和转移"使用MVC 3编写的遗留Web服务(以及用于管理它的网站)。我使用了visual studio" add - >码头支持"功能,我将我的网站放在一个容器中,如果我手动连接到正在运行的容器并安装MVC 3,网站将正常运行。我宁愿在构建容器时安装MVC 3。

dockerfile如下所示:

# escape=` (backtick)

FROM microsoft/aspnet:4.7.1-windowsservercore-1709
ARG source
WORKDIR /inetpub/wwwroot
COPY ${source:-obj/Docker/publish} .
RUN  C:\inetpub\wwwroot\AspNetMVC3Setup.exe /q

dockerfile的最后一行是不起作用的。我尝试了几种变体,但结果始终是某种类型的路径未找到错误。

其他尝试语法的示例:

RUN ["C:\inetpub\wwwroot\AspNetMVC3Setup.exe", "/q"]
RUN ["powershell.exe", "C:\inetpub\wwwroot\AspNetMVC3Setup.exe", "/q"]
RUN ["powershell.exe", ".\AspNetMVC3Setup.exe", "/q"]
RUN [".\AspNetMVC3Setup.exe", "/q"]
RUN AspNetMVC3Setup.exe /q

当我连接到正在运行的容器时,路径和文件名是正确的但是在构建期间文件是否真的存在?

如何将MVC安装作为容器构建的一部分运行?

错误示例:

13>Step 5/5 : RUN  C:\inetpub\wwwroot\AspNetMVC3Setup.exe /q
13> ---> Running in 3b7e8c30f2e0
13>[91mC:\inetpub\wwwroot\AspNetMVC3Setup.exe : The term
13>[0m[91m'C:\inetpub\wwwroot\AspNetMVC3Setup.exe' is not recognized as the name of a
13>cmdlet, function, script file, or operable program. Check the spelling of the
13>[0m[91mname, or if a path was included, verify that the path is correct and try again.
13>[0m[91mAt line:1 char:76
13>[0m[91m+ ... rence = 'SilentlyContinue'; C:\inetpub\wwwroot\AspNetMVC3Setup.exe /q
13>[0m[91m+                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
13>    + CategoryInfo          : ObjectNotFound: (C:\inetpub\wwwroot\AspNetMVC3Se
13>   tup.exe:String) [], ParentContainsErrorRecordException
13>    + FullyQualifiedErrorId : CommandNotFoundException


13>Step 5/5 : RUN ["C:\inetpub\wwwroot\AspNetMVC3Setup.exe", "/q"]
13> ---> Running in 7322410daf93
13>[91mAt line:1 char:77
13>[0m[91m+ ... ference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; [C:\inetp ...
13>+                                                                  ~
13>[0m[91mMissing ] at end of attribute or type literal.
13>[0m[91mAt line:1 char:78
13>+ ... ce = 'SilentlyContinue'; [C:\inetpub\wwwroot\AspNetMVC3Setup.exe, /q]
13>[0m[91m+                                
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
13>Unexpected token ':\inetpub\wwwroot\AspNetMVC3Setup.exe' in expression or
13>[0m[91mstatement.
13>At line:1 char:115
13>+ ... ce = 'SilentlyContinue'; [C:\inetpub\wwwroot\AspNetMVC3Setup.exe, /q]
13>+                                                                     ~
13>Missing argument in parameter list.
13>    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordEx
13>   ception
13>[0m[91m    + FullyQualifiedErrorId : EndSquareBracketExpectedAtEndOfAttribute
13>
13>Service 'adminmanagement' failed to build: The command 'powershell -Command $ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; ["C:\inetpub\wwwroot\AspNetMVC3Setup.exe", "/q"]' returned a non-zero code: 1
13>[0m


13>Step 5/5 : RUN ["powershell.exe", "C:\inetpub\wwwroot\AspNetMVC3Setup.exe", "/q"]
13> ---> Running in 44113a1005d2
13>[91mUnable to find type [powershell.exe,C:\inetpub\wwwroot\AspNetMVC3Setup.exe,
13>/q]. Details: The given assembly name or codebase was invalid. (Exception from
13>HRESULT: 0x80131047)
13>At line:1 char:76
13>[0m[91m+ ... yContinue'; [powershell.exe, C:\inetpub\wwwroot\AspNetMVC3Setup.exe,  ...
13>[0m[91m+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
13>    + CategoryInfo          : InvalidOperation: (powershell.exe,...C3Setup.exe
13>   , /q:TypeName) [], ParentContainsErrorRecordException
13>[0m[91m    + FullyQualifiedErrorId : TypeNotFoundWithMessage
13>[0m[91m
13>Service 'adminmanagement' failed to build: The command 'powershell -Command $ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; ["powershell.exe", "C:\inetpub\wwwroot\AspNetMVC3Setup.exe", "/q"]' returned a non-zero code: 1
 13>[0m

1 个答案:

答案 0 :(得分:0)

我无法在Visual Studio中使用它,但是通过使用非常相似的dockerfile,更改.dockerignore并直接从PowerShell调用docker,我能够在容器构建期间安装MVC 3。

Dockerfile:

*
!./bin/Release/Publish/*
!obj\Docker\publish\*
!obj\Docker\empty\

.dockerignore文件:

!./bin/Release/Publish/*

.dockerignore的更改是添加以下内容:

docker build -t [imagename] .
docker run -d --name [containername] [imagename]

Docker命令:

{{1}}