.net - 无法访问我的 Docker DotNet 核心网站

标签 .net docker dockerfile

我已经走进了死胡同。 我有一个 dotnet core 1.0.0 应用程序,我正在尝试启动并运行。 它在 Linux 和 Windows 上都能很好地工作。 现在我正在尝试将其放入docker中。 我制作了这个 docker 文件:

FROM microsoft/dotnet:1.0.0-preview2-sdk

COPY . /app
WORKDIR /app/app
RUN ["dotnet", "restore"]

ENTRYPOINT ["dotnet", "run"] 

它只是将代码复制到 docker 镜像中的应用程序文件夹中并恢复依赖项,然后运行它。当我尝试运行它时,它会在一切正常的情况下启动,并打印出与 Windows 或 Linux 启动时相同的内容。

Docker Console

运行项目的命令:

docker run --name dotNetWeb -p 8080:8080 kiksen1987/dotnetcore

代码链接: https://github.com/kiksen1987/dotnetcore

Docker 镜像链接: https://hub.docker.com/r/kiksen1987/dotnetcore/

我真的不知道出了什么问题。我或多或少采用了与我 99% 的其他项目相同的方法。

任何改进这个问题的反馈也很好:)

最佳答案

终于。

我找到了这篇博文:http://dotnetliberty.com/index.php/2015/11/26/asp-net-5-on-aws-ec2-container-service-in-10-steps/

尽管它使用了旧版本的 dotnet 核心,但我还是注意到了一个重要的点;

Notice that I’ve provided an extra parameter to the dnx web command to tell it to serve on 0.0.0.0 (rather than the default localhost). This will allow our web application to serve requests that come in from the port forwarding provided by Docker which defaults to 0.0.0.0.

这非常重要。

解决方案:

var host = new WebHostBuilder()
            .UseKestrel()
            .UseStartup<Startup>()
            .UseUrls("http://0.0.0.0:5000")
            .Build();

旧代码:

var host = new WebHostBuilder()
            .UseKestrel()
            .UseStartup<Startup>()
            .UseUrls("http://localhost:5000")
            .Build();

这非常令人沮丧,因为它似乎在 Linux 和 Windows 中完美运行,并且应用程序在 Docker 中启动,但从未收到任何请求。 希望这可以帮助其他一些可怜的人:)

关于.net - 无法访问我的 Docker DotNet 核心网站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38163752/

相关文章:

node.js - Nodejs 子进程以什么 Linux 用户身份运行?

docker - 如何不从 Docker 中的基础镜像继承标签?

nginx - Docker:如何管理开发和生产设置?

docker - 如何在 docker 容器内从头开始构建新应用程序?

c# - .Net 中的零舍入错误类?

c# - 为什么连接空字符串有效但调用 "null.ToString()"无效?

c# - 难看的文字问题

c# - 每个平台目标的不同程序集名称

docker - :2 mean when running Docker registry? 是什么意思

unix - 在 docker 容器中安装 ssh