You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

运行UA Cloud Library的Docker容器时出现证书错误求助

问题:WSL2环境下运行UA-CloudLibrary Docker容器时HTTPS证书错误

我在使用OPC Foundation的UA-CloudLibrary仓库,按照文档运行Docker容器,但在WSL2环境通过Visual Studio本地运行时遇到无法解决的错误,寻求解决建议。

执行命令及报错信息

~/sandbox/Subscription_Service/UA-CloudLibrary$ docker compose up
WARN[0000] The "APPDATA" variable is not set. Defaulting to a blank string.
WARN[0000] The "APPDATA" variable is not set. Defaulting to a blank string.
[+] Building 0.0s (0/0)
[+] Running 3/0
 ✔ Container ua-cloudlibrary-pgadmin-1          Created                                                                                                                                                               0.0s
 ✔ Container ua-cloudlibrary-ua-cloudlibrary-1  Created                                                                                                                                                               0.0s
 ✔ Container ua-cloudlibrary-db-1               Created                                                                                                                                                               0.0s
Attaching to ua-cloudlibrary-db-1, ua-cloudlibrary-pgadmin-1, ua-cloudlibrary-ua-cloudlibrary-1
ua-cloudlibrary-db-1               |
ua-cloudlibrary-db-1               | PostgreSQL Database directory appears to contain a database; Skipping initialization
ua-cloudlibrary-db-1               |
ua-cloudlibrary-pgadmin-1          | postfix/postlog: starting the Postfix mail system
ua-cloudlibrary-db-1               | 2023-12-10 07:20:04.991 UTC [1] LOG:  starting PostgreSQL 16.1 (Debian 16.1-1.pgdg120+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
ua-cloudlibrary-db-1               | 2023-12-10 07:20:04.997 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
ua-cloudlibrary-db-1               | 2023-12-10 07:20:04.998 UTC [1] LOG:  listening on IPv6 address "::", port 5432
ua-cloudlibrary-db-1               | 2023-12-10 07:20:05.010 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
ua-cloudlibrary-db-1               | 2023-12-10 07:20:05.038 UTC [29] LOG:  database system was shut down at 2023-12-10 07:10:25 UTC
ua-cloudlibrary-db-1               | 2023-12-10 07:20:05.084 UTC [1] LOG:  database system is ready to accept connections
ua-cloudlibrary-ua-cloudlibrary-1  | warn: Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository[60]
ua-cloudlibrary-ua-cloudlibrary-1  |       Storing keys in a directory '/app' that may not be persisted outside of the container. Protected data will be unavailable when container is destroyed.
ua-cloudlibrary-ua-cloudlibrary-1  | 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.
ua-cloudlibrary-ua-cloudlibrary-1  | To generate a developer certificate run 'dotnet dev-certs https'. To trust the certificate (Windows and macOS only) run 'dotnet dev-certs https --trust'.
ua-cloudlibrary-ua-cloudlibrary-1  | For more information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054.
ua-cloudlibrary-ua-cloudlibrary-1  |    at Microsoft.AspNetCore.Hosting.ListenOptionsHttpsExtensions.UseHttps(ListenOptions listenOptions, Action`1 configureOptions)
ua-cloudlibrary-ua-cloudlibrary-1  |    at Microsoft.AspNetCore.Hosting.ListenOptionsHttpsExtensions.UseHttps(ListenOptions listenOptions)
ua-cloudlibrary-ua-cloudlibrary-1  |    at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.AddressesStrategy.BindAsync(AddressBindContext context, CancellationToken cancellationToken)
ua-cloudlibrary-ua-cloudlibrary-1  |    at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindAsync(IEnumerable`1 listenOptions, AddressBindContext context, CancellationToken cancellationToken)
ua-cloudlibrary-ua-cloudlibrary-1  |    at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.BindAsync(CancellationToken cancellationToken)
ua-cloudlibrary-ua-cloudlibrary-1  |    at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.StartAsync[TContext](IHttpApplication`1 application, CancellationToken cancellationToken)
ua-cloudlibrary-ua-cloudlibrary-1  |    at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
ua-cloudlibrary-ua-cloudlibrary-1  |    at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
ua-cloudlibrary-ua-cloudlibrary-1  |    at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
ua-cloudlibrary-ua-cloudlibrary-1  |    at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
ua-cloudlibrary-ua-cloudlibrary-1  |    at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)
ua-cloudlibrary-ua-cloudlibrary-1  |    at Opc.Ua.Cloud.Library.Program.Main(String[] args) in /src/UACloudLibraryServer/Program.cs:line 39
ua-cloudlibrary-ua-cloudlibrary-1 exited with code 139
ua-cloudlibrary-pgadmin-1          | [2023-12-10 07:20:25 +0000] [1] [INFO] Starting gunicorn 20.1.0
ua-cloudlibrary-pgadmin-1          | [2023-12-10 07:20:25 +0000] [1] [INFO] Listening at: http://[::]:80 (1)
ua-cloudlibrary-pgadmin-1          | [2023-12-10 07:20:25 +0000] [1] [INFO] Using worker: gthread
ua-cloudlibrary-pgadmin-1          | [2023-12-10 07:20:25 +0000] [83] [INFO] Booting worker with pid: 83

已尝试操作

我按照错误提示执行了以下命令,结果显示已有有效证书,但问题未解决:

~/sandbox/Subscription_Service/UA-CloudLibrary$ dotnet dev-certs https

A valid HTTPS certificate is already present.

解决建议

  • 同步宿主证书到容器:WSL2宿主环境生成的证书无法被容器直接访问,需在docker-compose.yml的ua-cloudlibrary服务中添加挂载配置,将宿主的证书目录映射到容器内对应路径:
    volumes:
      - ~/.dotnet/corefx/cryptography/x509stores/my/:/root/.dotnet/corefx/cryptography/x509stores/my/
    
    保存后重新执行docker compose up。
  • 容器内生成证书:如果挂载无效,可尝试进入容器内部生成证书。先修改compose文件的ua-cloudlibrary服务command为bash,启动容器交互式模式,进入后执行dotnet dev-certs https,再重启服务。
  • 临时禁用HTTPS(仅开发环境):若仅用于测试,可修改应用配置或compose文件,让服务以HTTP模式启动,绕开证书问题。
  • 设置APPDATA环境变量:启动时提示APPDATA未设置,可在WSL2终端先执行export APPDATA="$HOME/.config",再运行docker compose up,排除该变量影响。

内容的提问来源于stack exchange,提问作者Pablo CA

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 05:18:09