如何使用 docker compose YAML 在 Azure 中安装 docker 卷

ps0*_*604 3 azure docker docker-compose

我正在尝试在 Azure 中部署 PosgreSQL Docker 容器。为此,我在 Azure 中创建了一个存储帐户和一个文件共享来存储 Docker 卷。

另外,我创建了 Docker Azure 上下文并将其设置为默认值。

为了创建卷,我运行:

volume create volpostgres --storage-account mystorageaccount
Run Code Online (Sandbox Code Playgroud)

我可以验证该卷是使用docker volume ls.

ID                            DESCRIPTION
mystorageaccount/volpostgres   Fileshare volpostgres in mystorageaccount storage account
Run Code Online (Sandbox Code Playgroud)

但是当我尝试使用 进行部署时docker compose up,我得到了

could not find volume source "volpostgres"
Run Code Online (Sandbox Code Playgroud)

这是不起作用的 YAML 文件。如何修复它?如何正确指向音量?

version: '3.7'
services:
  postgres:
    image: postgres:13.1
    container_name: cont_postgres
    networks:
      db:
        ipv4_address: 22.225.124.121
    ports:
      - "5432:5432"
    environment:  
      POSTGRES_PASSWORD: xxxxx
    volumes:
      - volpostgres:/var/lib/postgresql/data
networks:
   db:
    driver: bridge
    ipam:
      driver: default
      config:
        - subnet: 22.225.124.121/24
volumes:
  volpostgres:
     name: mystorageaccount/volpostgres
Run Code Online (Sandbox Code Playgroud)

Cha*_* Xu 6

您可以按照此处的步骤操作。并且volumesdocker-compose文件中的部分需要更改为:

volumes:
  volpostgres:
    driver: azure_file
    driver_opts:
     share_name: myfileshare
     storage_account_name: mystorageaccount
Run Code Online (Sandbox Code Playgroud)