每次使用ASP.NET Core应用程序构建Dockerfile时,它都会从Web Nuget商店下载程序集。
基本上我想用所有这些ASP.NET核心库(可能还有一些我经常使用的库)创建docker镜像。
根据我的理解,我试图重塑GAC。
所以,我的问题是有可能像GAC一样使用ASP.NET Core吗?或者,我的第二个想法,将ASP.NET核心库下载到容器,然后以某种方式在本地解析它。
我的目标是减少构建码头集装箱的时间。
更新
看起来不可能
答案 0 :(得分:5)
对于ASP.NET核心,只需使用dnu将应用程序构建到一个独立的文件夹中。
dnu publish
将输出构建项目并将其输出到/ bin / output。您可以使用许多选项,包括指定输出路径,选择框架或运行时,甚至更改启动Web的命令。
dnu publish --help
将为您提供更多详细信息。
答案 1 :(得分:2)
如果你想包含一个"包" (文件夹)包含您的应用程序,它的依赖项和运行时,然后您必须运行:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<system.serviceModel>
<services>
<service behaviorConfiguration="Default" name="MytestWCF_Entity.BookService">
<endpoint address="" behaviorConfiguration="restfulBehaviour" binding="webHttpBinding" bindingConfiguration="" contract="MytestWCF_Entity.IBookService" />
<host>
<baseAddresses>
<add baseAddress="http://localhost/bookservice"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="restfulBehaviour">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="Default">
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true" />
</system.webServer>
<connectionStrings><add name="SampleContext" connectionString="metadata=res://*/SampleModel.csdl|res://*/SampleModel.ssdl|res://*/SampleModel.msl;provider=System.Data.SqlClient;provider connection string="data source=(local);initial catalog=Sample;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /></connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
</entityFramework>
</configuration>
dnu publish --runtime <active/runtime name> [--no-source]
选项可编译所有内容并增加启动时间,但无法更改容器中的代码。
答案 2 :(得分:2)
现在有一个来自Microsoft的官方.NET Core Docker映像,带有所有需要的库。
你可以在这里得到它:
https://hub.docker.com/r/microsoft/aspnetcore/
如果您需要自定义它,请不要忘记您可以修改容器并使用&#34; docker commit&#34;创建自定义图像。