Azure:无法将 volumeMount 与 MariaDB 容器实例一起使用

Azure: Unable to use volumeMount with MariaDB container instance

我正在尝试将我的 MariaDB 存储在 Azure 存储帐户中

在我的 YAML 中,我用这个来定义 MariaDB 图像:

- name: mariadb
  properties:
    image: mariadb:latest
    environmentVariables:
      - name: "MYSQL_INITDB_SKIP_TZINFO"
        value: "1"
      - name: "MYSQL_DATABASE"
        value: "metrics"
      - name: "MYSQL_USER"
        value: "user"
      - name: "MYSQL_PASSWORD"
        value: "password"
      - name: "MYSQL_ROOT_PASSWORD"
        value: "root_password"
    ports:
    - port: 3306
      protocol: TCP
    resources:
      requests:
        cpu: 1.0
        memoryInGB: 1.5
    volumeMounts:
    - mountPath: /var/lib/mysql
      name: filesharevolume

我的卷定义如下所示:

volumes:
- name: filesharevolume
  azureFile:
    sharename: <share-name>
    storageAccountName: <name>
    storageAccountKey: <key>

然而,当此图像启动时,它会因错误而终止,解释说 ibdata1 文件大小与配置文件中的内容不匹配。

如果我删除 volumeMount,数据库映像工作正常。

有没有我遗漏的东西?

对于此问题,原因已在 Note 中显示:

Mounting an Azure Files share to a container instance is similar to a Docker bind mount. Be aware that if you mount a share into a container directory in which files or directories exist, these files or directories are obscured by the mount and are not accessible while the container runs.

文件共享挂载到现有目录,然后覆盖该目录。而MariaDB会根据要求重建ibdata1文件,但它是空的,与之前的不匹配。

对于Azure File Share的使用,我建议您只将File Share挂载到之前不存在的目录中,以持久化数据。或者目录下的文件不影响应用的正常运行