【问题标题】:Azure Fileshare - Using Docker-Compose to Mount Different Subfolders/Files to volume on ACIAzure Fileshare - 使用 Docker-Compose 将不同的子文件夹/文件挂载到 ACI 上的卷
【发布时间】:2021-10-12 03:12:06
【问题描述】:

我在 docker-compose 文件上有不同的服务,这些服务会提取一些图像以在 ACI 上创建容器。 当我将不同的目录和子文件夹挂载到 docker 容器时,我的本地机器上一切正常:

volumes:
 - folder/sub_folder/sub/folder:/etc/nginx/certs

但是在 ACI 上启动实例需要使用我使用的 azure_file 驱动程序,但我无法从该文件共享中将子文件夹挂载到路径。

我在撰写文件中创建了一个卷:

  volumes:
      data-volume:
        driver: azure_file
        driver_opts:
          share_name: acishare
          storage_account_name: storageaccount
          storage_account_key: /run/secrets/storage_account_key.txt

我已经尝试过这个容器

  services:
   app:  
    volumes:
      - data-volume:/etc/nginx/

上面的工作正常,但是挂载了文件共享的主目录,这是可以理解的,因为没有指定目录。

我做了一些研究,发现在 AKS 上,可以将文件的目录指定为共享名称。用反斜杠()尝试了这个,但我收到一条错误消息,说文件共享不存在:

volumes:
  data-volume:
    driver: azure_file
    driver_opts:
      share_name: acishare/sub_directory/sub_directory
      storage_account_name: storageaccount
      storage_account_key: /run/secrets/storage_account_key.txt

我也尝试添加卷的路径,但这也不起作用:

volumes:
  - data-volume/sub_directory/sub_directory:/etc/nginx/

将 Azure 文件共享的不同子​​文件夹挂载到 ACI 的正确方法是什么?

PS:我的代码库在 github 上,我正在使用工作流将 upload-batch 文件复制到 azure 文件共享,因为我需要将子文件夹复制(挂载)到容器中的 wwwroot 目录。 repo 还有一些配置文件需要直接挂载到容器中。这些文件也不在根文件夹中,而是在不同的子文件夹中。

如果有更好的选择来处理这种情况,我不介意。我曾尝试使用 blob 存储,但无法找到解决方法。

【问题讨论】:

  • 你解决了吗?我也有兴趣安装 Azure 文件共享子目录。
  • 您好,如果我的回答对您有帮助,您可以接受它作为答案(点击答案旁边的复选标记,将其从灰色切换为已填充。)。这对其他社区成员可能是有益的。谢谢

标签: docker docker-compose docker-volume azure-container-instances azure-files


【解决方案1】:

也许你可以试试这个:

volumeMounts:
    -  mountPath: /main/path
       subPath: data
       name: whatevername

查看以下链接,希望对您有所帮助。 azure subdirs

干杯!

【讨论】:

    【解决方案2】:

    我尝试重现但无法将单个文件/文件夹从 Azure 文件共享装载到 Azure 容器实例。

    部署容器并挂载卷

        az container create \
        --resource-group $ACI_PERS_RESOURCE_GROUP \
        --name hellofiles \
        --image mcr.microsoft.com/azuredocs/aci-hellofiles \
        --dns-name-label aci-demo \
        --ports 80 \
        --azure-file-volume-account-name $ACI_PERS_STORAGE_ACCOUNT_NAME \
        --azure-file-volume-account-key $STORAGE_KEY \
        --azure-file-volume-share-name $ACI_PERS_SHARE_NAME \
        --azure-file-volume-mount-path /aci/logs/
    

    .

     STORAGE_KEY=$(az storage account keys list --resource-group $ACI_PERS_RESOURCE_GROUP --account-name $ACI_PERS_STORAGE_ACCOUNT_NAME --query "[0].value" --output tsv)
        echo $STORAGE_KEY
    

    这里还有一件事要注意,无论您将在文件共享中更新什么文件,在您将文件共享作为卷挂载到容器之后,它也会在容器中更新。 这可能是我们无法将特定文件和文件夹挂载为容器中的卷的原因。

    这也有一些限制,

    • 您只能将 Azure 文件共享装载到 Linux 容器。在概览中详细了解 Linux 和 Windows 容器组的功能支持差异。

    • 您只能装载整个共享,而不能装载其中的子文件夹。

    • Azure 文件共享卷装载需要 Linux 容器以 root 身份运行。

    • Azure 文件共享卷装载仅限于 CIFS 支持。

    • 共享无法以只读方式装载。

    • 您可以挂载多个卷,但不能使用 Azure CLI,而必须使用 ARM 模板。

    参考:https://docs.microsoft.com/en-us/azure/container-instances/container-instances-volume-azure-files https://www.c-sharpcorner.com/article/mounting-azure-file-share-as-volumes-in-azure-containers-step-by-step-demo/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-05-31
      • 1970-01-01
      • 1970-01-01
      • 2021-05-24
      • 2016-10-08
      • 2019-01-09
      • 2019-01-03
      相关资源
      最近更新 更多