Docker和ASP.NET Core 2.1预览版1

4
我已经从这里安装了ASP.NET Core 2.1预览版1和最新版本的Visual Studio。然后我按照以下步骤操作:文件>新建项目>ASP.NET Core Web应用程序>选择API,检查启用Docker支持(操作系统:Linux)无身份验证。这样可以很好地生成项目模板以及带有docker compose文件的Docker项目。它可以成功构建并拉取所有所需的映像,但是,当我尝试从Visual Studio中运行它时,似乎不起作用,在日志中我看到如下所示内容:

Content root path: /app
Now listening on: http://[::]:80
...
Request starting HTTP/1.1 GET http://localhost:32778/ Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request starting HTTP/1.1 GET http://localhost:32778/

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

Could not get any response There was an error connecting to http://localhost:32778/api/values.

但是!Docker日志显示发出了请求:

Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request starting HTTP/1.1 GET http://localhost:32778/api/values
[40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Hosting.Internal.WebHost[1] Request starting HTTP/1.1 GET http://localhost:32778/api/values
[40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Hosting.Internal.WebHost[2] Request finished in 14.4873ms 307 Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request finished in 14.4873ms 307

我错过了什么?如果我使用IIS Express运行默认项目,则一切正常。编辑:我刚刚在ASP.NET Core 2.0上测试了这个问题,一切都正常。
2个回答

8

正如 @andrewbadera 所指出的,仓库已经更改:

SDK

旧: microsoft/aspnetcore-build:2.0

新: microsoft/dotnet:2.1-sdk

ASP NET

旧: microsoft/aspnetcore:2.0

新: microsoft/dotnet:2.1-aspnetcore-runtime

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

Visual Studio 模板正在生成:

SDK => microsoft/aspnetcore:2.1

ASP NET => microsoft/aspnetcore-build:2.1


1
我也在使用Docker上遇到了netcoreapp2.1的问题。你确定Docker镜像已经成功拉取了吗?因为当我创建一个新项目时,创建的Dockerfile中有以下内容:
FROM microsoft/aspnetcore:2.1 AS base
//...
//...
FROM microsoft/aspnetcore-build:2.1 AS build

从我在microsoft docker repo中看到的情况来看,这些镜像根本不存在
在VS中的输出显示:
========== 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

我找到的最接近的图片是:
microsoft/aspnetcore:2.1.0-preview1
microsoft/aspnetcore-build:2.1.300-preview1

应用程序可以运行,但是有一个问题:在VS中调试时,调试器无法触发任何断点(因为未加载PDB符号,我不知道为什么会发生这种情况)。当创建新的ASP.NET Core 2.0项目时,所有我刚才描述的都能正常工作。

我也是。 - andrewbadera

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接