我遵循了 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 上运行它吗?
欢迎任何建议。谢谢。
最佳答案
您是否使用了 aspnet-docker github project 中的正确 Docker 镜像? ?
有关在 Docker 上运行 ASP.NET 5 的文章,网址为 msdn - link
编辑:
根据文章 - 你失踪了
RUN ["kpm", "restore"]
在Dockerfile
中。
2015 年 5 月适用于 ASP.NET 5 的文章: https://alexanderzeitler.com/articles/Running-ASP.NET-5-beta4-in-Docker-with-DNX-runtime/
关于c# - 无法在 Docker 上运行 asp.net mvc 6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30054505/