在Docker中启动一个准系统MVC C#ASP.NET项目给出了“编译错误”
要开始,如果溢出不是正确的Stack站点,请告诉我!另外,如果您需要查看其他文件,请随时询问。在Docker中启动一个准系统MVC C#ASP.NET项目给出了“编译错误”
我开始了一个示例Visual Studio C#/ ASP.NET MVC应用程序,尝试将其作为概念验证放入Docker中,以了解如何配置这两个部分一起工作。它在本地工作,但通过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]
我的工作流是发布到文件系统,然后通过下面的dockerfile构建docker镜像。我使用该选项来“预编译”源代码(让我对错误感到困惑)。以下是我认为相关的文件(添加到该文章中的标签后的评论,而不是实际的文件中)。
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>
我用下面的命令来构建/运行环境:
docker build -t testapp .
docker run -d --name test -p 20012:20012 testapp
的-p似乎并不想为了工作,我尝试去码头的IP上的那个端口,它总是被拒绝,所以我直接去了码头'从检查中获得知识产权。
事情我已经尝试过失败的不同级别:
- 暴露出dockerfile,从来没有帮助或伤害。
- CMD /入口点我非常好可能会使用他们错了一直,但我读入口点就无关紧要了,微软/ ASPNET基本图像
- 剥去了这让我进一步的验证/实体(其实我刚开始一个新的项目,而不他们开始)
任何帮助,将不胜感激!
更新1:
使用的答案来解决问题之后,它成功地构建和作为是我的最终目标打印服务器的IP(泊坞窗容器)来显示如何在负载平衡/群集运作。对于任何对预先构建的Docker镜像(在Windows容器中)感兴趣的人来说,它将打印出您所打开的Docker镜像的IP,作为Docker负载平衡/ Swarming的概念证明,该镜像位于hub.docker.com下图片名称acmiles/aspnet_printserverip
。随意查看它,但它只是一个示例项目,增加了在索引页上打印Docker容器的IP的逻辑。以下是我用于构建映像的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应用程序时,我遇到了同样的问题。我周围的房子试图解决这个问题,并在周末花了很多时间!我尝试将各种临时文件夹的权限设置为各种帐户,并尝试将应用程序池设置为使用本地配置文件运行。
我终于通过将应用程序池帐户添加到本地管理员组来使其工作。这不是最终的解决方案,但它运作良好,并指明了我需要为其分配权限的帐户的正确方向。
这是我的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;
希望它有帮助。
感谢
贾里德
另一个解决方法是在不同的网站工作。在我的码头文件中,我删除了默认网站并添加了一个新网站。
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'
不确定是否需要IISRESET,这只是我以前运行的脚本的剩余部分。 –
这确实奏效,我相信重要的一行是'RUN Add-LocalGroupMember -Group'Administrators'-Member'IIS AppPool \ DefaultAppPool';'但我还没有确认。你认为'IISRESET'没有必要。在我确认需要什么之后,我会发布我的dockerfile。这次真是万分感谢!我希望这可以帮助其他人,我花了几天的时间在这个上! – AntonMiles
我相信会有一种方法来授予比完全本地管理员更少的权限,它可能只需要修改权限到c:\ windows \ temp或类似的,但我还没有时间来测试。 –