[英]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:
这些是我正在采取的确切步骤:
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.