4

我已经从这里安装了 ASP.NET Core 2.1 预览版 1和 Visual Studio 的最新预览版。

然后我按照以下步骤操作:文件 > 新建项目 > ASP.NET Core Web 应用程序 > 选择API、检查Enable Docker Support (Os: Linux)No Authentication.

这很好地生成了项目模板,以及带有 docker compose 文件的 Docker 项目。这构建得很好,并提取了所有需要的图像。但是,当我尝试在 Visual Studio 中使用 Docker 运行它时,它似乎不起作用。

在日志中,我看到以下内容:

内容根路径:/app
现在监听:http://[::]:80
...
请求开始 HTTP/1.1 GET http://localhost:32778/ Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request开始 HTTP/1.1 GET http://localhost:32778/

现在,当我尝试对http://localhost:32778/api/values进行 GET (使用 Postman)时,没有看到任何响应:

无法得到任何响应连接到http://localhost:32778/api/values时出错。

但!Docker 日志显示正在发出请求:

Microsoft.AspNetCore.Hosting.Internal.WebHost:信息:请求开始 HTTP/1.1 GET http://localhost:32778/api/values
[40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Hosting.Internal.WebHost[ 1] 请求开始 HTTP/1.1 GET http://localhost:32778/api/values
[40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Hosting.Internal.WebHost[2] 请求在 14.4873ms 307 Microsoft 完成。 AspNetCore.Hosting.Internal.WebHost:信息:请求在 14.4873 毫秒内完成 307

我在这里想念什么?如果我使用 IIS Express 运行默认项目,一切都会按预期运行。

编辑:我刚刚在 ASP.NET Core 2.0 上对此进行了测试,一切正常。

4

2 回答 2

8

正如@andrewbadera 指出的那样,存储库发生了变化:

SDK

老的 :microsoft/aspnetcore-build:2.0

新的:microsoft/dotnet:2.1-sdk

ASP 网络

老的 :microsoft/aspnetcore:2.0

新的:microsoft/dotnet:2.1-aspnetcore-runtime

我不知道为什么 Visual Studio 的模板还没有使用它,但很快他们可能会解决这个问题。

Visual Studio 模板正在生成:

开发工具包 =>microsoft/aspnetcore:2.1

ASP 网络 =>microsoft/aspnetcore-build:2.1

于 2018-04-27T14:09:37.343 回答
1

I'm also struggling with netcoreapp2.1 on Docker. Are you sure that docker images are pulled down successfully? Because when I'm creating a new project, the created Dockerfile has:

FROM microsoft/aspnetcore:2.1 AS base
//...
//...
FROM microsoft/aspnetcore-build:2.1 AS build

and from what I can see in the microsoft docker repo, those images simply do not exist (!).

The output in VS shows:

========== Pulling Images ==========
Pulling missing Docker images. To cancel this download, close the command prompt window. To disable image auto-pull, see Tools > Options > Container Tools.
docker pull microsoft/aspnetcore:2.1
docker pull failed

The closest images I found are:

microsoft/aspnetcore:2.1.0-preview1
microsoft/aspnetcore-build:2.1.300-preview1

and the app works, BUT there is another problem: while debugging in VS, the debugger doesn't hit any breakpoints (because PDB symbols are not loaded, I don't know why that happens).

Everything I just described, works when creating a new ASP.NET Core 2.0 project.

于 2018-03-27T14:35:48.327 回答