Docker中的ASP.NET 5.0 beta 8无法启动

我一直在Docker容器中运行一个使用ASP.NET 5.0 beta 7的网站,使用正式的Docker镜像 – https://github.com/aspnet/aspnet-docker – 工作正常。

我最近更新了我的项目到beta 8,并将Dockerfile更改为使用Docker镜像的Beta 8版本。 当我在Windows计算机上本地运行它时,一切工作正常,无论是使用Visual Studio使用IIS Express启动项目,还是使用Kestrel运行它。

但是,然后我把它推到我的Dokku服务器,似乎并没有正常启动。 我没有从容器输出中得到任何错误,但是我有一个Dokku用来确保Web服务器已经启动的CHECKS文件,并且失败了(表明它没有正确启动,或者没有按照它应该进行监听) 。 我试图删除CHECKS,我也无法连接到它 – 我从nginx得到一个坏的网关消息。

我不知道这是为什么发生,因为当我推到Dokku时,我得到以下回应:

... remote: [1G-----> Attempt 5/5 Waiting for 10 seconds ...[K remote: [1G CHECKS expected result:[K remote: [1G http://localhost/ => "My Website"[K remote: Could not start due to 1 failed checks.[K remote: [1G ! [K remote: [1Gcurl: (7) Failed to connect to 172.17.2.14 port 5000: Connection refused[K remote: [1G ! Check attempt 5/5 failed.[K remote: [1G=====> mywebsite container output:[K remote: [1G info : [Microsoft.Framework.DependencyInjection.DataProtectionServices] User profile is available. Using '/root/.local/share/ASP.NET/DataProtection-Keys' as key repository; keys will not be encrypted at rest.[K remote: [1G Hosting environment: Production[K remote: [1G Now listening on: http://localhost:5000[K remote: [1G Application started. Press Ctrl+C to shut down.[K remote: [1G=====> end mywebsite container output[K` ... 

这看起来很奇怪,因为它看起来像是开始,但在检查失败之后。 正如我所说,取消支票意味着它成功部署,但是我无法连接到它。

我的Dockerfile是:

 FROM microsoft/aspnet:1.0.0-beta8 # Install NPM 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 Gulp RUN npm install -g gulp COPY . /app WORKDIR /app RUN ["dnu", "restore"] WORKDIR ./src/mywebsite RUN ["npm", "install"] RUN ["gulp", "min"] EXPOSE 5000 ENTRYPOINT dnx kestrel 

我遇到了类似的问题,我无法访问在Windows上的Docker容器中运行的ASP.NET 5 beta 8网站,我收到了与您相同的消息。

我不确定这是否会成为同样的问题,但这是我如何解决这个问题。 症状看起来相似。 这个问题与这条线有关:

 Now listening on: http://localhost:5000 

有趣的是,当我做了docker ps ,发现端口5000被转发到了0.0.0.0 ,而不是localhost

解决scheme

我解决这个问题的方法是在project.json更新我的web命令以指定要使用的实际networking接口:

 "commands": { "web": "Microsoft.AspNet.Server.Kestrel --server.urls http://0.0.0.0:5000", "ef": "EntityFramework.Commands" }, 

一旦我这样做了,我就可以看到Kestrel现在正在监听Docker为我转发的同一个界面,并且我能够毫无问题地访问网站。

替代使用Dockerfile

您也可以在ENTRYPOINT中更新您的ENTRYPOINT命令:

 ENTRYPOINT ["dnx", "web", "--server.urls", "http://0.0.0.0:5000"] 

(您将需要用Docker正在暴露的确切接口replace0.0.0.0 )。

博客文章/ Writeup

如果你想阅读更多关于这个(或者如何在ASP.NET 5上运行Docker),请看看我的博客文章: http : //dotnetliberty.com/index.php/2015/10/25/ ASP-净-5-磨合-泊坞窗上,窗/