InvalidOperationException while 运行 asp.net in a linux machine under docker
InvalidOperationException while running asp.net in a linux machine under docker
我刚刚使用新的 .NET 支持设置了我的 linux 机器。
- 使用本教程:http://docs.asp.net/en/latest/getting-started/installing-on-linux.html
拥有这个 dockerfile:
FROM microsoft/aspnet:1.0.0-beta5
# Copy the project into folder and then restore packages
COPY . app
WORKDIR app
RUN ["dnu","restore"]
# Open this port in the container
EXPOSE 5000
# Start application
ENTRYPOINT ["dnx",".", "web"]
运行docker build .
成功
当 运行 # docker run -p 8080:5000 dockerfile
我得到这个异常:
System.InvalidOperationException: No service for type 'Microsoft.Framework.Runtime.IApplicationEnvironment' has been registered.
at Microsoft.Framework.DependencyInjection.ServiceProviderExtensions.GetRequiredService (IServiceProvider provider, System.Type serviceType) [0x00000] in <filename unknown>:0
at Microsoft.Framework.DependencyInjection.ServiceProviderExtensions.GetRequiredService[IApplicationEnvironment] (IServiceProvider provider) [0x00000] in <filename unknown>:0
at Microsoft.AspNet.Hosting.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 at Microsoft.Dnx.Runtime.Common.EntryPointExecutor.Execute (System.Reflection.Assembly assembly, System.String[] args, IServiceProvider serviceProvider) [0x00000] in <filename unknown>:0
at Microsoft.Dnx.ApplicationHost.Program+<>c__DisplayClass3_0.<ExecuteMain>b__0() [0x00000] in <filename unknown>:0
at System.Threading.Tasks.Task`1[System.Threading.Tasks.Task`1[System.Int32]].InnerInvoke() [0x00000] in <filename unknown>:0
at System.Threading.Tasks.Task.Execute () [0x00000] in <filename unknown>:0
这是我的完整构建日志
我在这里做错了什么? 运行 在 windows 中与 dnx . web
相同的项目成功启动了我的 webapi。
自己解决了。发现在安装教程的过程中,它正在安装一个旧的单声道版本。你需要 Mono 4.x,根据这个 post http://blog.bananacoding.com/blog/first-impressions-of-aspnet-and-visual-studio-code-on-osx
所以我做了以下事情:
- 使用 .net 卸载单声道
- 正在清除它
- 使用 mono 网站上的安装说明,安装 mono 4-x
- 使用
apt-get -o Dpkg::Options::="--force-overwrite" -f install
我被迫覆盖所有内容,因为我遇到了一些库的错误
- dnvm 安装最新
- 使我的项目适应最新版本(参见网上的多个更新 post)
- dnu 恢复
- dnx 红隼
完成!
我刚刚使用新的 .NET 支持设置了我的 linux 机器。
- 使用本教程:http://docs.asp.net/en/latest/getting-started/installing-on-linux.html
拥有这个 dockerfile:
FROM microsoft/aspnet:1.0.0-beta5 # Copy the project into folder and then restore packages COPY . app WORKDIR app RUN ["dnu","restore"] # Open this port in the container EXPOSE 5000 # Start application ENTRYPOINT ["dnx",".", "web"]
运行
docker build .
成功当 运行
# docker run -p 8080:5000 dockerfile
我得到这个异常:System.InvalidOperationException: No service for type 'Microsoft.Framework.Runtime.IApplicationEnvironment' has been registered. at Microsoft.Framework.DependencyInjection.ServiceProviderExtensions.GetRequiredService (IServiceProvider provider, System.Type serviceType) [0x00000] in <filename unknown>:0 at Microsoft.Framework.DependencyInjection.ServiceProviderExtensions.GetRequiredService[IApplicationEnvironment] (IServiceProvider provider) [0x00000] in <filename unknown>:0 at Microsoft.AspNet.Hosting.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0 at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&) at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 at Microsoft.Dnx.Runtime.Common.EntryPointExecutor.Execute (System.Reflection.Assembly assembly, System.String[] args, IServiceProvider serviceProvider) [0x00000] in <filename unknown>:0 at Microsoft.Dnx.ApplicationHost.Program+<>c__DisplayClass3_0.<ExecuteMain>b__0() [0x00000] in <filename unknown>:0 at System.Threading.Tasks.Task`1[System.Threading.Tasks.Task`1[System.Int32]].InnerInvoke() [0x00000] in <filename unknown>:0 at System.Threading.Tasks.Task.Execute () [0x00000] in <filename unknown>:0
这是我的完整构建日志
我在这里做错了什么? 运行 在 windows 中与 dnx . web
相同的项目成功启动了我的 webapi。
自己解决了。发现在安装教程的过程中,它正在安装一个旧的单声道版本。你需要 Mono 4.x,根据这个 post http://blog.bananacoding.com/blog/first-impressions-of-aspnet-and-visual-studio-code-on-osx
所以我做了以下事情:
- 使用 .net 卸载单声道
- 正在清除它
- 使用 mono 网站上的安装说明,安装 mono 4-x
- 使用
apt-get -o Dpkg::Options::="--force-overwrite" -f install
我被迫覆盖所有内容,因为我遇到了一些库的错误 - dnvm 安装最新
- 使我的项目适应最新版本(参见网上的多个更新 post)
- dnu 恢复
- dnx 红隼
完成!