我正在尝试将azure 文件共享挂载到Web App for Containers (linux)服务。这是一个带有角度前端的 .net Core 3 web api 应用程序。当我挂载本地驱动器以加载与文件共享中完全相同的文件时,应用程序容器在本地完美运行。
根据docker docs for azure file share我应该将我的 docker compose 文件设置为以下内容:
version: '3.4'
services:
webui:
image: ${DOCKER_REGISTRY-}webui
build:
context: .
dockerfile: src/WebUI/Dockerfile
environment:
- "UseInMemoryDatabase=false"
- "ASPNETCORE_ENVIRONMENT=Production"
- "ConnectionStrings__DefaultConnection=Server="
- "ASPNETCORE_Kestrel__Certificates__Default__Path=/security/mycertfile.pfx"
- "ASPNETCORE_Kestrel__Certificates__Default__Password=Your_password123"
ports:
- "5000:5000"
- "5001:5001"
volumes:
- mcpdata:"/security:/security"
restart: always
volumes:
mcpdata:
driver: azure_file
driver_opts:
share_name: sharename
storage_account_name: storageaccountname
我可以确认文件共享包含环境变量中引用的文件:mcpdata/security/mycertfile.pfx
问题:
当容器由服务运行时,它会给出错误:
System.InvalidOperationException:加载证书时出错。找不到文件“/security/mycert.pfx”。
我累了:
- 因为容器失败了,我无法通过 ssh 进入它来检查文件。所以我在本地从 azure 容器注册表中提取图像,然后执行docker export -o dump.tar。然后我提取文件并且没有创建安全文件夹。
- 我还尝试通过从 docker compose 文件中删除顶级挂载定义,直接在 docker compose 文件中引用命名文件共享。删除的代码如下所示:
volumes:
mcpdata:
driver: azure_file
driver_opts:
share_name: sharename
storage_account_name: storageaccountname
问题:
有人可以帮我将 azure 文件共享连接到我的容器,或者帮我确认容器失败时文件的挂载位置。
编辑1:
尝试使用 azure cli 添加文件共享挂载。我使用以下命令将文件共享挂载添加到我的 Web 应用程序:
az webapp config storage-account add --resource-group "rgname" --name "appname" --slot development --custom-id fsmount001 --storage-type AzureFiles --share-name "sname" --account-name "aname" --access-key "key" --mount-path /
此命令有效并创建文件挂载,但是我仍然收到在 /security/ 文件夹中找不到证书文件的错误
如果我通过 kudu 而不是容器本身 bash 进入应用程序,我可以看到文件挂载存在并且在 Web 应用程序的根目录中命名为 security。
编辑 2:解决方案
使用以下命令设置文件挂载:
az webapp config storage-account add --resource-group "rgname" --name "appname" --slot development --custom-id fsmount001 --storage-type AzureFiles --share-name "sname" --account-name "aname" --access-key "key" --mount-path /security/security/
在 docker compose 中,我使用:
volumes:
- fsmount001: /security:/security
在 appsettings.Production.json 中:
"IdentityServer": {
"Key": {
"Type": "File",
"FilePath": "/security/mycert.pfx",
"Password": "password"
}
}
这是我的文件挂载设置在配置 - > 路径映射下的 azure 门户中的样子:
文件挂载内部是一个名为 security 的文件夹,其中包含证书文件。
感谢查尔斯的帮助,我希望这对其他人有帮助!