NET 5.0 控制臺應用程式,我想在 docker 容器中運行
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.SignalR.Client;
using System.Net.Http;
using System.Threading;
namespace pi_worker
{
class Program
{
private const string _url = "*server_url*";
static async Task Main(string[] args)
{
using (HttpClient client = new HttpClient())
{
await client.GetAsync($"{_url}/*endpointName*");
}
}
}
我正在使用 dockerfile 和命令構建我的容器:
docker build -t worker .
docker run worker.
FROM mcr.microsoft.com/dotnet/runtime:5.0
COPY bin/Release/net5.0/publish .
ENTRYPOINT ["dotnet", "pi-worker.dll"]
但是對于第二個命令容器啟動,我收到了這個錯誤
Unhandled exception. System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.
---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid because of errors in the certificate chain: UntrustedRoot
at System.Net.Security.SslStream.SendAuthResetSignal(ProtocolToken message, ExceptionDispatchInfo exception)
at System.Net.Security.SslStream.ForceAuthenticationAsync[TIOAdapter](TIOAdapter adapter, Boolean receiveFirst, Byte[] reAuthenticationData, Boolean isApm)
at System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(Boolean async, Stream stream, SslClientAuthenticationOptions sslOptions, CancellationToken cancellationToken)
--- End of inner exception stack trace ---
at System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(Boolean async, Stream stream, SslClientAuthenticationOptions sslOptions, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.GetHttpConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.SendAsyncCore(HttpRequestMessage request, HttpCompletionOption completionOption, Boolean async, Boolean emitTelemetryStartStop, CancellationToken cancellationToken)
at pi_worker.Program.Main(String[] args) in *path_to_project*\pi-worker\pi-worker\Program.cs:line 25
at pi_worker.Program.<Main>(String[] args)
我嘗試了一些谷歌解決方案,但沒有一個有幫助
uj5u.com熱心網友回復:
錯誤訊息說您在 Docker 中的作業人員無法識別您服務器的 SSL 證書。因此,無法建立 HTTPS 連接。為了修復它,您需要以某種方式將服務器中的證書添加到存盤在 docker 容器中的受信任證書中。這篇文章可能有助于做到這一點。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/459682.html
上一篇:C#如何在第一個數字上拆分字串?
