Home > database >  Deploying Postgres DB in Azure Container App
Deploying Postgres DB in Azure Container App

Time:11-22

Hi I am new to Azure and I got a requirement to deploy Postgres DB to Azure Container app. I know its not a good practice to host a DB inside a containerize environment.

I followed this enter image description here

I created a VNET since I need to select TCP as the Ingress type and mapped the target port and and exposed port port as 5432 to 5432

enter image description here

After I deploy the application and try to connect to the DB using Pgadmin I am getting the following error.

enter image description here

I want to make sure the Postgres DB running successfully inside the Azure Container App and need to connect from Pgadmin.

CodePudding user response:

There are 2 problems here:

  • Your app definition is incorrect (particularly around "Command override")
  • You could fix that part and Postgres would start, but you will run into a persistent storage issue. Azure ContainerApps today only supports enter image description here

    or using the azure cli

    az containerapp create \
      --name $POSTGRES_INSTANCE_NAME \
      --resource-group $RESOURCE_GROUP \
      --environment $CONTAINERAPPS_ENVIRONMENT  \
      --image docker.io/postgres:15 \
      --secrets pgpass="$POSTGRES_PASSWORD" \
      --env-vars POSTGRES_USER="$POSTGRES_USER" POSTGRES_DB="$POSTGRES_DB" POSTGRES_PASSWORD=secretref:pgpass \
      --transport tcp \
      --target-port 5432 \
      --ingress external \
      --min-replicas 1 \
      --max-replicas 1
    

    you could change --ingress external to --ingress internal then deploy pgadmin on the same environment. Then pgadmin should be able to reach postgres on $POSTGRES_INSTANCE_NAME:5432

    to deploy pgadmin

    az containerapp create \
      --name pgadmin \
      --resource-group $RESOURCE_GROUP \
      --environment $CONTAINERAPPS_ENVIRONMENT  \
      --image dpage/pgadmin4:6.15 \
      --secrets pgpass="$PGADMIN_PASSWORD" \
      --env-vars PGADMIN_DEFAULT_EMAIL="$PGADMIN_EMAIL" PGADMIN_LISTEN_PORT="8080" PGADMIN_DEFAULT_PASSWORD=secretref:pgpass \
      --transport http \
      --target-port 8080 \
      --ingress external \
      --min-replicas 1 \
      --max-replicas 1
    
  • Related