我正在学习将blazor服务器应用程序加载到docker容器(aspnet core 3.0.201)上。我已经成功地将镜像加载到容器上。我可以创建一个应用程序来构建它,但在运行blazor服务器应用程序时,我收到了这样的警告:
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.这是一个警告,但我知道将密钥加载到容器上并不是一个好的做法,所以我想修复这个警告。任何指导都是值得感谢的。
发布于 2020-06-19 10:04:30
您收到的警告是因为ASP.NET核心DataProtection将密钥存储在主目录(/root/.aspnet/DataProtection- keys )中,因此当容器重新启动时,密钥会丢失,这可能会使服务崩溃。
这可以通过在以下位置持久化密钥来解决:
有关ASP.NET DataProtection的更多详细信息:
使用以下命令将外部卷(C:/temp-keys)挂载到docker容器卷(/root/.aspnet/DataProtection-Keys)
docker run -d -v /c/temp-keys:/root/.aspnet/DataProtection-Keys container-name
此外,您还需要更新Starup.cs - ConfigureServices以配置DataProtection策略
services.AddDataProtection().PersistKeysToFileSystem(new DirectoryInfo(@"C:\temp-keys\"))
.UseCryptographicAlgorithms(new AuthenticatedEncryptorConfiguration()
{
EncryptionAlgorithm = EncryptionAlgorithm.AES_256_CBC,
ValidationAlgorithm = ValidationAlgorithm.HMACSHA256
});https://stackoverflow.com/questions/61452280
复制相似问题