在Docker中启动一个准系统MVC C#ASP.NET项目给出了“编译错误”

要开始,如果溢出不是正确的Stack站点,请让我知道! 另外,如果您需要查看其他文件,请随时询问。

我开始了一个示例Visual Studio C#/ ASP.NET MVC应用程序,尝试将Docker作为概念validation,以了解如何configuration这两个部分一起工作。 它在本地工作,但通过Docker部署时,会引发错误。

Server Error in '/' Application. Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS0016: Could not write to output file 'c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\e22c2559\92c7e946\App_Web_index.cshtml.a8d08dba.w8h4d0pg.dll' -- 'The directory name is invalid. ' Source Error: [No relevant source lines] 

我的工作stream程是发布到文件系统,然后通过下面的dockerfile构builddocker镜像。 我使用该选项来“预编译”源代码(让我感到困惑的错误)。 以下是我认为相关的文件(添加到此文章中的标签之后的评论,而不是实际的文件中)。

dockerfile

 FROM microsoft/aspnet COPY ./ /inetpub/wwwroot #this copies from the published folder, which contains 'bin' 

web.config中

 <?xml version="1.0" encoding="utf-8"?> <!-- For more information on how to configure your ASP.NET application, please visit http://go.microsoft.com/fwlink/?LinkId=301880 --> <configuration> <system.web> <customErrors mode="Off"/> </system.web> <appSettings> <add key="webpages:Version" value="3.0.0.0"/> <add key="webpages:Enabled" value="false"/> <add key="ClientValidationEnabled" value="true"/> <add key="UnobtrusiveJavaScriptEnabled" value="true"/> </appSettings> <system.web> <compilation debug="true" targetFramework="4.0"/> <httpRuntime targetFramework="4.0"/> </system.web> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed"/> <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35"/> <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35"/> <bindingRedirect oldVersion="1.0.0.0-1.5.2.14234" newVersion="1.5.2.14234"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35"/> <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35"/> <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/> <bindingRedirect oldVersion="1.0.0.0-5.2.2.0" newVersion="5.2.2.0"/> </dependentAssembly> </assemblyBinding> </runtime> </configuration> 

我使用以下命令来构build/运行环境:

 docker build -t testapp . docker run -d --name test -p 20012:20012 testapp 

-p似乎不想工作,我已经试图去docker的IP端口,它总是被拒绝,所以我直接去检查得到的docker的IP。

我尝试过不同程度的失败:

  • 在dockerfile中EXPOSE,从来没有帮助或伤害。
  • CMD / ENTRYPOINT我很可能一直在使用它们,但是我读了ENTRYPOINT与microsoft / aspnet base image无关
  • 剥去了authentication/实体,让我进一步(我实际上刚开始一个新的项目,没有他们开始)

任何帮助,将不胜感激!

更新1:

使用答案解决问题后,它成功构build,并按照我的最终目标打印服务器(docker容器)的IP,以显示负载平衡/ Swarming如何工作。 对于任何对预先构build的docker镜像(在windows容器中)感兴趣的人来说,这个镜像都会打印出Docker镜像的IP,作为Docker负载均衡/ Swarming的概念certificate,该镜像位于hub.docker.com下图像名称acmiles/aspnet_printserverip 。 随意查看它,但它只是一个示例项目,添加了逻辑在索引页上打印Docker容器的IP。 以下是我用来构build图像的dockerfile的最终版本。

 FROM microsoft/aspnet RUN New-Item c:\testapp -type directory WORKDIR /testapp COPY ./outputRelease/ . RUN Remove-WebSite -Name 'Default Web Site' RUN New-Website -Name 'webapp' -Port 80 -PhysicalPath 'c:\testapp' -ApplicationPool '.NET v4.5' 

在尝试获取在Docker中工作的现有MVC应用程序时,我遇到了同样的问题。 我周围的房子试图解决这个问题,并在周末花了好几个小时! 我试图设置各种临时文件夹的权限到各种帐户,我试图设置应用程序池运行本地configuration文件。

我最终通过将应用程序池帐户添加到本地pipe理员组来工作。 这不是一个最终的解决scheme,但它的工作,并指出我正确的方向,我需要分配权限的帐户。

这是我的Dockerfile;

 FROM microsoft/aspnet SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] ARG source WORKDIR /inetpub/wwwroot COPY ${source:-obj/Docker/publish} . RUN Add-LocalGroupMember -Group 'Administrators' -Member 'IIS AppPool\DefaultAppPool'; \ IISRESET; 

希望能帮助到你。

谢谢

贾里德

另一个解决方法是在另一个网站上工作。 在我的docker文件中,我删除了默认的网站,并添加一个新的。

 RUN New-Item c:\webapp -type directory RUN Remove-WebSite -Name 'Default Web Site' RUN New-Website -Name 'webapp' -Port 80 -PhysicalPath 'c:\webapp' -ApplicationPool '.NET v4.5'