azure - 使用 docker-compose 将 Azure 文件共享挂载到 Linux 容器的 Web 应用程序

标签 azure docker docker-compose azure-web-app-service azure-web-app-for-containers

我正在尝试将 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

在我的网络应用程序的配置中,我创建了以下文件挂载: enter image description here

我可以确认文件共享包含环境变量中引用的文件:mcpdata/security/mycertfile.pfx

问题:

当容器由服务运行时,它会给出错误:

System.InvalidOperationException: There was an error loading the certificate. The file '/security/mycert.pfx' was not found.

我累了什么:

  1. 由于容器出现故障,我无法通过 ssh 进入容器来检查文件。因此,我从本地的 azure 容器注册表中提取镜像,然后执行 docker export -o dump.tar 。然后,我提取文件,但未创建安全文件夹。
  2. 我还尝试通过从 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 门户中的样子: enter image description here

文件挂载内有一个名为 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/

相关文章:

azure - 从 Microsoft 帐户登录不适用于 Multi-Tenancy Azure AD 应用程序

php - Azure 通知中心 - 401 MissingToken : The authorization header was not found

perl - 维护 docker 镜像时应该如何处理 Perl 模块更新?

python-3.x - 我们可以一起在docker中设置PHP 7.x和Python 3.x吗?

Azure 媒体服务 REST API 错误 MissingApiVersionParameter

c - 检测 Azure Linux VM 中的临时磁盘

mongodb - 在同一台主机的两个不同容器上运行 MongoDB 和 Redis

java - Big Query Java 客户端的代理设置

docker - 如何在单个docker中为多个Web应用程序传递多个属性文件?

docker - 在使用docker-compose启动webapp之前如何填充Elasticsearch数据库?