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

ASP.NET 5.0 beta 8 in Docker doesn't start

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

我最近将我的项目更新为 beta 8,并更改了 Docker 文件以使用 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`
...

这看起来很奇怪,因为看起来它正在启动,但在检查失败之后。正如我所说,删除检查意味着它已成功部署,但我无法连接到它。

我的 Docker 文件是:

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

我 运行 遇到了类似的问题,我无法访问我的 ASP.NET 5 beta 8 网站 运行 在 Docker 容器中 Windows, 我收到了和你一样的信息。

我不确定这是否对您来说是同一个问题,但我是这样解决的。症状看起来很相似。该问题与此处的这一行有关:

Now listening on: http://localhost:5000

有趣的是,当我执行 docker ps 时,它显示端口 5000 被转发到 0.0.0.0,而不是 localhost

解决方案

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

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

执行此操作后,我可以看到 Kestrel 现在正在监听 Docker 为我转发的同一界面,我可以毫无问题地访问该网站。

替代使用Docker文件

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

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

(您需要将 0.0.0.0 替换为 Docker 公开的确切界面)。

博客Post/写文章

如果您想了解更多相关信息(或如何使用 ASP.NET 5 在 Windows 上 运行 Docker),请在此处查看我的博客文章: http://dotnetliberty.com/index.php/2015/10/25/asp-net-5-running-in-docker-on-windows/