无法在Docker上运行asp.net mvc 6

时间:2015-05-05 13:33:31

标签: c# asp.net-mvc docker visual-studio-code

我按照Visual Studio Code的指导创建了一个ASP.NET MVC应用程序。我可以在我的本地(Windows 8)上运行它。但是当我试图将它发布到Docker时,问题就发生了。

我的dockerfile喜欢

FROM microsoft/aspnet:1.0.0-beta4

#install npm in docker image
RUN apt-get update && apt-get install -y curl
RUN curl -sL https://deb.nodesource.com/setup | bash -
RUN apt-get install -y nodejs

#install bower and grunt
RUN npm install -g bower
RUN npm install -g grunt-bower-cli
RUN npm install -g grunt
RUN npm install -g grunt-cli
RUN npm install -g grunt-bower-task

COPY project.json /app/

WORKDIR /app

RUN ["dnu", "restore"]

COPY . /app

CMD ["cd", "/app/"]
CMD ["npm", "install"]
CMD ["bower", "install"]

EXPOSE 5001

ENTRYPOINT ["dnx", "kestrel"]

然后我试着建立它

docker build -t thangchung/webdemo .

docker run -i -p 8080:5001 -t thangchung/webdemo

当我运行上面的代码时,它总是抛出异常

System.InvalidOperationException: Unable to resolve project 'kestrel' from /app/kestrel
  at Microsoft.Framework.Runtime.ApplicationHostContext..ctor (IServiceProvider serviceProvider, System.String projectDirectory, System.String packagesDirectory, System.String configuration, System.Runtime.Versioning.FrameworkName targetFramework, ICache cache, ICacheContextAccessor cacheContextAccessor, INamedCacheDependencyProvider namedCacheDependencyProvider, IAssemblyLoadContextFactory loadContextFactory, Boolean skipLockFileValidation) [0x00000] in <filename unknown>:0
  at Microsoft.Framework.Runtime.DefaultHost.Initialize (Microsoft.Framework.Runtime.DefaultHostOptions options, IServiceProvider hostServices) [0x00000] in <filename unknown>:0
  at Microsoft.Framework.Runtime.DefaultHost..ctor (Microsoft.Framework.Runtime.DefaultHostOptions options, IServiceProvider hostServices) [0x00000] in <filename unknown>:0
  at Microsoft.Framework.ApplicationHost.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

有人能让我知道为什么我无法在Docker上运行它吗?

欢迎任何建议。感谢。

2 个答案:

答案 0 :(得分:3)

您是否使用了来自aspnet-docker github project的正确Docker镜像?

关于在msdn上运行ASP.NET 5的文章 - link

修改

根据文章 - 你错过了

RUN ["kpm", "restore"]
Dockerfile中的

2015年5月适用于ASP.NET 5的文章: https://alexanderzeitler.com/articles/Running-ASP.NET-5-beta4-in-Docker-with-DNX-runtime/

答案 1 :(得分:1)

使用从k到dnx的更新,您现在必须为包含project.json的目录提供路径参数。那么过去是什么

k kestrel

变为

dnx . kestrel