Azure WebApps + Azure 文件与多容器共享

问题描述

我一直在尝试使用我的 API 设置我的 Postgresql 数据库。我的 API 在 Azure WebApps 上,数据库在 Azure 文件共享上。

以下是我的docker compose文件

version: '3.3'

services:
   db:
     image: postgres
     volumes:
       - db_path:/var/lib/postgresql/data
     restart: always
     environment:
        POSTGRES_USER: dbuser
        POSTGRES_PASSWORD: dbuser's_password
        POSTGRES_DB: db_1

   api:
     depends_on:
       - db
     image: <my registry>.azurecr.io/api:latest
     ports:
       - "80:80"
     restart: always

我的 WebApp -> 配置 -> 路径映射如下

enter image description here

它确实已部署,但我在 Azure 文件共享的位置找不到我的数据库文件。现在,当我重新部署时,我可以在 Log Stream 中看到以下内容

enter image description here

有人可以告诉我我做错了什么吗?为什么我的数据库不在我的 Azure 文件共享中?

提前致谢

编辑

连同查尔斯的建议如下:

enter image description here

我还更新了我的 docker-compose.yml 文件,如下所示。我所做的更改是我保持卷名与映射名称相同并添加driver_opts:

version: '3.8'

services:
   db:
     image: MysqL
     volumes:
       - MysqL:/var/lib/MysqL
     environment:
       - MysqL_DATABASE=dbname
       - MysqL_ROOT_PASSWORD=MyRootPassword!
       - MysqL_USER=dbUser_1
       - MysqL_PASSWORD=dbUser_1'sPassword
     restart: always

   api:
     depends_on:
       - db
     entrypoint: ["./wait_for.sh","db:3306","-t","3600","--","execute","api"] #waiting very long enough to set the db server up and running
     image: <my registry's url>/api:latest
     ports:
       - "80:80"
     restart: always

volumes:
  MysqL:
        driver: azure_file
        driver_opts:
          share_name: Azure_Share_Name
          storage_account_name: Azure_Storage_Account_Name
          storageaccountkey: Azure_Key

解决方法

这是一个已知问题。使用具有 Azure 文件共享的持久卷挂载时,挂载路径将具有 root 所有者和组,并且您无法更改它。所以如果应用程序需要特殊用户的路径,像这个问题,Postgresql需要挂载路径/var/lib/postgresql/datapostgres所有者,那么就无法实现。

请注意,您随路径映射提供的屏幕截图显示了错误的挂载路径以及 YAML 文件中的配置。这可能是一个错误。