Why my Azure Container Instances (Postgresql database with persistence storage/multi-containers) from Docker Compose fail to start up? (with no error message/log)

Kenny Wong (HK) 40 Reputation points
2024-01-15T11:14:05.86+00:00

I followed this link to deploy multiple containers to Azure Container instances with docker compose file with some slight modifications.

https://video2.skills-academy.com/en-us/azure/container-instances/tutorial-docker-compose

My containers contain one server container and one postgressql db container. The server container is able to start up but the db container fail to start up but I can't find any error message from the command line or on Azure User's image

The docker compose file is able to run locally, the only change I have made is on the "volumes:" part (last part of my docker compose yaml file) to mount the azure file share to the container for persistent storage and store some SQL scripts (in the sql file share) that will run when the database initialize (is this possible on Azure?). I have already created the two file shares in my storage account User's image

I am not sure if I have done this part correctly. Below is my yaml file

services:
  server:
    build:
      context: ./backend
      dockerfile: Dockerfile
    image: <my azure container registry>.azurecr.io/<my image name>
    # volumes:
    #   - ./app/:/code/app/
    command: uvicorn app.main:app --reload --workers 1 --host 0.0.0.0 --port 8000
    ports:
      - 8000:8000
    environment:
		<some environment variable here>
    depends_on:
      - db
 
  db:
    image: postgres:13-alpine
    volumes:
      - postgres-data:/var/lib/postgresql/data/
      - sql:/docker-entrypoint-initdb.d # Azure
      # - ./sql:/docker-entrypoint-initdb.d # local
    environment:
		<some environment variable here>
    ports:
      - 5432:5432 
	  
volumes:
    postgres-data:
      driver: azure_file
      driver_opts:
        share_name: postgres-data
        storage_account_name: <my storage account>
        storage_account_key: <my storage account access key>
    sql:
      driver: azure_file
      driver_opts:
        share_name: sql
        storage_account_name: <my storage account>
        storage_account_key: <my storage account access key>


Thank you

Azure Container Registry
Azure Container Registry
An Azure service that provides a registry of Docker and Open Container Initiative images.
426 questions
Azure Container Instances
Azure Container Instances
An Azure service that provides customers with a serverless container experience.
672 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Anveshreddy Nimmala 3,460 Reputation points Microsoft Vendor
    2024-01-17T07:47:11.5866667+00:00

    Hello Kenny Wong (HK), Welcome to microsoft Q&A, thankyou for posting your query. you are having trouble starting the db container in your docker-compose file. have you tried checking the logs of the db container to see if there are any error messages there? You can check the logs of the db container by running the following command: docker-compose logs db This will show you the logs of the db container. If there are any error messages, they should be visible in the logs. Regarding your question about running SQL scripts when the database initializes, it is possible to do this in Azure. You can mount an Azure file share to the container and store the SQL scripts in the file share. Then, you can use the docker-entrypoint-initdb.d directory to run the SQL scripts when the container initializes. In your docker-compose file, you have already mounted the sql file share to the db container at /docker-entrypoint-initdb.d. This means that any SQL scripts that you place in the sql file share will be executed when the db container initializes. hope this helps you