Search code examples
azuredockerdocker-composeazure-container-instances

How can I make a file accessible to Azure container instance


thanks in advance for your help. I am really new to docker and I am trying to deploy a container group to ACI using docker context and docker compose. I need a certain license file to be accessible when the instance starts.

I have tried quite a few things like adding the file to azure file share and blog and mounting it is as volume but no luck. I have added my docker compose file. Please guide me how can I achieve the above scenario?

version: "3.5"

services:
  api:
    image: myimagefromdockerhub 
    container_name: api
    deploy: 
      resources:
         reservations:
          cpus: '2'
          memory: 3G
    environment:
      Sqlname:*****
      SqlPass:*****
    volumes:
      - license:/app/extBin/unix_x64/cpu/license
    ports:
      - "8080:8080"
    networks:
      - api-network
    depends_on:
      - "db-postgres"
    restart: always

  db-postgres:
    image: bitnami/postgresql:14.5.0-debian-11-r35
    container_name: db-postgres
    restart: unless-stopped
    volumes:
      - postgre-data:/var/lib/postgresql/data
    environment:
      POSTGRES_DB: "db"
      POSTGRES_USER: "user"
      POSTGRES_PASSWORD: "****"
    ports:
      - "5432:5432"
    networks:
      - api-network
    healthcheck:
      test: ["CMD", "curl", "-f", "http://api:41101/ || exit"]
      interval: 30s
      timeout: 30s
      retries: 3

networks:
  api-network:
    driver: bridge

volumes:
  postgre-data:
   driver: azure_file
   driver_opts:
      share_name: myfileshare
      storage_account_name: storageaccountname
  license:
   driver: azure_file
   driver_opts:
      share_name: license
      storage_account_name: storageaccountname

when I run docker compose up -d it deploys alright but the file is not present and postgre keeps terminating and restarting. I am more concerned about the file not being present.

any help will be appreciated.


Solution

  • I tried reproducing the same in my environment using the below steps and got the results as expected. Check if you have followed all these steps and able to ressolve the issue.

    As a first step, I created docker context using the command docker context create and set as the default context. enter image description here

    Next, I have created a storage account with fileshare (tier=Hot) in the same resource group as the docker context .

    I have uploaded a sample certificate to the fileshare.

    enter image description here

    Next, I modified your Dockerfile slightly and ran using docker-compose up command and verfied whether the file existed in the azure portal as below.

    version: "3.5"
    
    services:
      api:
        image: nginx 
        container_name: api
        deploy: 
          resources:
             reservations:
              cpus: '2'
              memory: 3G
        volumes:
          - license:/app/extBin/unix_x64/cpu/license
        ports:
          - "80:80"
        networks:
          - api-network
        restart: always
    
    networks:
      api-network:
        driver: bridge
    
    volumes:
      license:
       driver: azure_file
       driver_opts:
          share_name: license
          storage_account_name: licensestrgaccountvjy
    

    enter image description here

    enter image description here