How to mount azure storage to docker path

Zhi Xing Liu (CSI Interfusion Inc) 20 Reputation points Microsoft Vendor
2023-12-07T14:40:53.8633333+00:00

I followed this article https://video2.skills-academy.com/en-us/azure/container-instances/container-instances-volume-azure-files to mount storage account to docker container path to persist postgres data

but after stopping and starting , data is gone.

could anyone help with me?

version: "3.6"
services:
  postgres:
    image: postgres:15
   ** volumeMounts:
      - mountPath: /var/lib/postgresql/data
        name: filesharevolume**
    restart: always
  graphql-engine:
    image: hasura/graphql-engine:v2.29.0
    ports:
      - "8080:8080"
    restart: always
    environment:
      HASURA_GRAPHQL_ENABLE_CONSOLE: "true"
      HASURA_GRAPHQL_DEV_MODE: "true"
      HASURA_GRAPHQL_ENABLED_LOG_TYPES: startup, http-log, webhook-log, websocket-log, query-log
      HASURA_GRAPHQL_METADATA_DEFAULTS: '{"backend_configs":{"dataconnector":{"athena":{"uri":"http://data-connector-agent:8081/api/v1/athena"},"mariadb":{"uri":"http://data-connector-agent:8081/api/v1/mariadb"},"mysql8":{"uri":"http://data-connector-agent:8081/api/v1/mysql"},"oracle":{"uri":"http://data-connector-agent:8081/api/v1/oracle"},"snowflake":{"uri":"http://data-connector-agent:8081/api/v1/snowflake"}}}}'
    depends_on:
      data-connector-agent:
        condition: service_healthy
  data-connector-agent:
    image: hasura/graphql-data-connector:v2.29.0
    restart: always
    ports:
      - 8081:8081
    environment:
      QUARKUS_LOG_LEVEL: ERROR
      QUARKUS_OPENTELEMETRY_ENABLED: "false"
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8081/api/v1/athena/health"]
      interval: 5s
      timeout: 10s
      retries: 5
      start_period: 5s
**volumes:
- name: filesharevolume
  azureFile:
    sharename: sharedfolder
    storageAccountName: leostorageaccount2 
    storageAccountKey: uyQcwH+b0dwK****************v+2NKOLI+AStOTglYw==**

Azure Container Instances
Azure Container Instances
An Azure service that provides customers with a serverless container experience.
687 questions
Azure Storage Accounts
Azure Storage Accounts
Globally unique resources that provide access to data management services and serve as the parent namespace for the services.
3,085 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Amira Bedhiafi 22,311 Reputation points
    2023-12-09T16:59:25.3766667+00:00

    In Docker Compose, the volume configuration is slightly different from Kubernetes. The volumeMounts syntax you used seems to be more in line with Kubernetes. In Docker Compose, you should define your volumes under the volumes section of a service and then define the volume details at the bottom of the file.

    
        version: "3.6"
    
        services:
    
          postgres:
    
            image: postgres:15
    
            volumes:
    
              - filesharevolume:/var/lib/postgresql/data
    
            restart: always
    
          # ... other services ...
    
          # Define your other services here
    
        volumes:
    
          filesharevolume:
    
            driver: azure_file
    
            driver_opts:
    
              share_name: sharedfolder
    
              storage_account_name: leostorageaccount2
    
              storage_account_key: uyQcwH+b0dwK...v+2NKOLI+AStOTglYw==
    
    

    Make sure that the Azure File Share (sharedfolder) exists in your Azure Storage Account (leostorageaccount2) and that the storage account key is correct. After making these changes, redeploy your services and verify that the data persists across container restarts.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.