简体   繁体   English

Visual Studio 2019 - Docker 4.1.1 - Web 添加容器编排后应用停止工作

[英]Visual Studio 2019 - Docker 4.1.1 - Web App Stops Working After Adding Container Orchestration

This is sort of strange.这有点奇怪。 As soon as I add docker orchestration in Visual Studio 2019 my Web Application stops working.一旦我在 Visual Studio 2019 中添加 docker 编排,我的 Web 应用程序就会停止工作。 These are the exact steps that I am taking:这些是我正在采取的确切步骤:

  1. Launch Visual Studio 2019 (16.11.3)启动 Visual Studio 2019 (16.11.3)
  2. Create new Project创建新项目
  3. Select "ASP.NET Core Web App", and click on Next Select“ASP.NET Core Web App”,点击下一步
  4. Accept default Project Name and Location, and click on Next接受默认的项目名称和位置,然后单击下一步
  5. Specify, target framework as .NET 5.0 (Current), Auth Type: Individual Accounts, Check the box for Configure for HTTPS. At this moment I am not checking the Enable docker and enable razor runtime.指定目标框架为 .NET 5.0(当前),身份验证类型:个人帐户,选中配置 HTTPS 框。此时我没有选中启用 docker 并启用 razor 运行时。 Click on Create点击创建
  6. On the welcome screen click on Connected services, and configure on the Secrets.json (local) (finish, close that)在欢迎屏幕上单击已连接的服务,然后在 Secrets.json(本地)上进行配置(完成,关闭)
  7. Right-Click on my project, add, Container Orchestration Support右击我的项目,添加Container Orchestration Support
  8. Select "Docker Compose" as the orchestrator, and linux as the target os Select “Docker Compose” 作为协调器,linux 作为目标操作系统
  9. It appears that Visual Studio creates a docker-compose project to the solution, as well as some dockerfiles to the project. Visual Studio 似乎为解决方案创建了一个 docker-compose 项目,并为该项目创建了一些 dockerfile。 The output also shows that the containers are being built and eventually says they are ready. output 还显示正在构建容器并最终表示它们已准备就绪。

However my docker desktop shows them in this state但是我的 docker 桌面在这个 state 中显示了它们

在此处输入图像描述

The error shows as follows错误显示如下

在此处输入图像描述

The text of that error shows:该错误的文本显示:

warn: Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository[60]

      Storing keys in a directory '/root/.aspnet/DataProtection-Keys' that may not be persisted outside of the container. Protected data will be unavailable when container is destroyed.

warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]

      No XML encryptor configured. Key {a6907c05-45f2-4dc3-93ac-5d59ce2b2873} may be persisted to storage in unencrypted form.

crit: Microsoft.AspNetCore.Server.Kestrel[0]

      Unable to start Kestrel.

      System.InvalidOperationException: Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found or is out of date.

      To generate a developer certificate run 'dotnet dev-certs https'. To trust the certificate (Windows and macOS only) run 'dotnet dev-certs https --trust'.

      For more information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054.

         at Microsoft.AspNetCore.Hosting.ListenOptionsHttpsExtensions.UseHttps(ListenOptions listenOptions, Action`1 configureOptions)

         at Microsoft.AspNetCore.Hosting.ListenOptionsHttpsExtensions.UseHttps(ListenOptions listenOptions)

         at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.AddressesStrategy.BindAsync(AddressBindContext context)

         at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindAsync(IEnumerable`1 listenOptions, AddressBindContext context)

         at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.BindAsync(CancellationToken cancellationToken)

         at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.StartAsync[TContext](IHttpApplication`1 application, CancellationToken cancellationToken)

Unhandled exception. System.InvalidOperationException: Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found or is out of date.

To generate a developer certificate run 'dotnet dev-certs https'. To trust the certificate (Windows and macOS only) run 'dotnet dev-certs https --trust'.

For more information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054.

   at Microsoft.AspNetCore.Hosting.ListenOptionsHttpsExtensions.UseHttps(ListenOptions listenOptions, Action`1 configureOptions)

   at Microsoft.AspNetCore.Hosting.ListenOptionsHttpsExtensions.UseHttps(ListenOptions listenOptions)

   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.AddressesStrategy.BindAsync(AddressBindContext context)

   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindAsync(IEnumerable`1 listenOptions, AddressBindContext context)

   at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.BindAsync(CancellationToken cancellationToken)

   at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.StartAsync[TContext](IHttpApplication`1 application, CancellationToken cancellationToken)

   at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)

   at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)

   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)

   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)

   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)

   at WebApplication7.Program.Main(String[] args) in /src/WebApplication7/Program.cs:line 16

I was expecting since I didn't do anything custom yet that the orchestrator would just simply "work" at this point but it doesn't.我一直在期待,因为我还没有做任何定制,所以编排器此时只会简单地“工作”,但事实并非如此。

I noticed that my Trust ASP.NET Core SSL certificate is "Prompt Me", but I never receive the prompt我注意到我的 Trust ASP.NET Core SSL 证书是“提示我”,但我从未收到提示

在此处输入图像描述

I also try and do what is suggested in the error.我也尝试按照错误中的建议进行操作。 So I press the trash can icon in my docker desktop for the orchestration.因此,我按下 docker 桌面上的垃圾桶图标进行编排。 I then modify the Dockerfile inside of the project as follows, notice the extra run that I add before the entry point there.然后我如下修改项目内部的 Dockerfile,注意我在入口点之前添加的额外运行。

#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY ["WebApplication7/WebApplication7.csproj", "WebApplication7/"]
RUN dotnet restore "WebApplication7/WebApplication7.csproj"
COPY . .
WORKDIR "/src/WebApplication7"
RUN dotnet build "WebApplication7.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "WebApplication7.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
RUN dotnet dev-certs https
ENTRYPOINT ["dotnet", "WebApplication7.dll"]

I save the file and rebuild the solution and press the debug / start button (F5) for docker compose.我保存文件并重建解决方案,然后按 docker 组合的调试/启动按钮 (F5)。 It says the containers are ready again but now there are no ports exposed, thus no where to browse to, and no logs.它说容器再次准备就绪,但现在没有端口暴露,因此没有浏览到的地方,也没有日志。 I can access the cli for the container but that's it.我可以访问容器的 cli,仅此而已。

在此处输入图像描述

What am I doing wrong?我究竟做错了什么? Why is this not just simply working OOB with Visual Studio?为什么这不只是简单地将 OOB 与 Visual Studio 一起使用?

Something that does work though is if I take that extra RUN line out of my Dockerfile that I added, then set my web project as the startup project, I am able to debug and run that.但是,如果我从我添加的 Dockerfile 中取出额外的 RUN 行,然后将我的 web 项目设置为启动项目,我就可以调试并运行它。 But again, once I set the docker-compose project as the startup project and try to debug that, I am dead in the water again.但是,一旦我将 docker-compose 项目设置为启动项目并尝试对其进行调试,我又陷入了困境。

Inside of your project go to Solution Explorer > Solution > Properties > launchsettings.json .在您的项目 go 中到 Solution Explorer > Solution > Properties > launchsettings.json

There should be a Docker section that Visual Studio adds automatically, if not add the Docker launch settings below.应该有 Visual Studio 自动添加的 Docker 部分,如果没有,请添加下面的 Docker 启动设置。 You can choose which ports you want your app to listen on.您可以选择您希望应用监听的端口。

 "Docker": { "commandName": "Docker", "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}", "publishAllPorts": true, "useSSL": true, "DockerfileRunArguments": "add custom arguments here such as -.network my.network", "httpPort": 5000, "sslPort": 5001 } }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 docker 中运行 Visual Studio 2019 .net web 应用程序无法连接到外部 MySql 服务器 - Running Visual Studio 2019 .net web app in docker can't connect to external MySql server 更新到 Visual Studio 2019 16.8.0 后应用清单验证错误 - App manifest validation error after update to visual studio 2019 16.8.0 自动完成功能停止工作 Accord.Math、Visual Studio 2019、C# - Autocomplete stops working Accord.Math, Visual Studio 2019, C# 从 Visual Studio 2019 中的 C# 解决方案返回 cmake 项目时,Resharper 智能感知停止工作 - when going back to cmake project from C# solution in visual studio 2019 Resharper intellisense stops working Visual Studio 重做快捷键 Ctrl + Y 复制后停止工作 - Visual Studio Redo shortcut Ctrl + Y stops working after copy Visual Studio 2019 - 在 WebApp 中添加 WebJob 项目 - Visual Studio 2019 - Adding WebJob project in WebApp Visual Studio 2019 Edge Browser for javascript 调试停止在错误的行 - visual studio 2019 Edge Browser for javascript debugging stops at wrong line 评论选择在 Visual Studio 社区 2019 中不起作用 - Comment selection not working in visual studio community 2019 Visual Studio 2019 C# 突出显示不起作用? - Visual Studio 2019 C# highlighting not working? 使用不起作用的 Visual Studio 2019 自动导入 - Auto import usings not working Visual Studio 2019
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM