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

2023-12-10

我正在尝试安装天蓝色文件共享 to a 容器 Web 应用程序 (Linux)服务。这是一个具有 Angular 前端的 .net Core 3 Web API 应用程序。当我安装本地驱动器以加载与文件共享中完全相同的文件时,应用程序容器在本地完美运行。

根据Azure 文件共享的 docker 文档我应该将我的 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

In the configuration for my web app I have created the following file mount: enter image description here

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

PROBLEM:

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

System.InvalidOperationException:加载证书时出错。找不到文件“/security/mycert.pfx”。

我累了什么:

  1. 因为容器失败,我无法通过 ssh 进入容器来检查文件。所以我从本地的azure容器注册表中提取图像,然后执行docker 导出 -o dump.tar。然后我提取文件,但未创建安全文件夹。
  2. 我还尝试通过从 docker compose 文件中删除顶级挂载定义,直接在 docker compose 文件中引用命名文件共享。删除的代码如下所示:
volumes:
  mcpdata:
    driver: azure_file
    driver_opts:
      share_name: sharename
      storage_account_name: storageaccountname

问题:

有人可以帮助我将天蓝色文件共享连接到我的容器,或者帮助我确认容器发生故障时文件的安装位置。

EDIT 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"
    }
  }

This is what my file mount settings look like in the azure portal under configuration -> path mappings: enter image description here

文件挂载内有一个名为 security 的文件夹,其中包含证书文件。

感谢查尔斯的帮助,我希望这对其他人有帮助!


您所遵循的步骤适用于 ACI,不适用于 网络应用程序。要将 Azure 文件共享挂载到容器的 Azure Web App,您只需按照以下步骤操作将存储链接到您的应用程序.

并且您需要更改 docker-compose 文件volumes:

From:

volumes:
       - mcpdata:"/security:/security"

Into:

volumes:
       - custom-id:/security/security/

custom-id 是您在 CLI 命令中使用的内容。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

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

随机推荐