我正在尝试将 azure 文件共享装载到容器 Web 应用程序 (linux) 服务。这是一个带有 Angular 前端的 .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: There was an error loading the certificate. The file '/security/mycert.pfx' was not found.
我累了什么:
- 由于容器出现故障,我无法通过 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 而不是容器本身攻击应用程序,我可以看到文件挂载存在,并且在 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 的文件夹,其中包含证书文件。
感谢 Charles 的帮助,我希望这对其他人有帮助!
最佳答案
您所遵循的步骤适用于 ACI,而不适用于 网络应用程序。要将 Azure 文件共享挂载到容器的 Azure Web App,只需按照 Link storage to your app 中的步骤操作即可。 .
并且您需要更改 volumes
中的 docker-compose 文件:
来自:
volumes:
- mcpdata:"/security:/security"
进入:
volumes:
- custom-id:/security/security/
custom-id 是您在 CLI 命令中使用的内容。
关于azure - 使用 docker-compose 将 Azure 文件共享挂载到 Linux 容器的 Web 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64287843/