Sign inSign up

aalhalim/postgres-azure

By aalhalim

•Updated 5 months ago

Image
0

9.5K

aalhalim/postgres-azure repository overview

⁠PostgreSQL Azure Files Compatible Image

This is a custom PostgreSQL Docker image optimized for Azure File Shares (SMB/CIFS) storage in Azure Container Apps.

⁠The Problem

Azure Files uses the SMB/CIFS protocol which doesn't support Unix file permissions properly. Standard PostgreSQL images fail because:

  1. PostgreSQL requires the data directory to have mode 0700 or 0750
  2. Azure Files mounts files with fixed permissions (typically 0777)
  3. chmod and chown operations fail silently or error out
  4. PostgreSQL's initdb checks these permissions and fails

⁠The Solution

This image includes:

  1. Custom entrypoint script that handles Azure Files limitations
  2. Proper PGDATA configuration using a subdirectory (/var/lib/postgresql/data/pgdata)
  3. Optimized PostgreSQL settings for Azure infrastructure
  4. Pre-configured network access for containerized environments

⁠Usage

⁠Docker Compose
services:
  postgres:
    image: ghcr.io/dev-halim/postgres-azure:16
    environment:
      POSTGRES_USER: myuser
      POSTGRES_PASSWORD: mypassword
      POSTGRES_DB: mydatabase
    volumes:
      - postgres-data:/var/lib/postgresql/data
    ports:
      - "5432:5432"

volumes:
  postgres-data:
⁠Azure Container Apps (JSON Config)
{
  "app_name": "postgres",
  "image": "ghcr.io/dev-halim/postgres-azure:16",
  "cpu": 0.5,
  "memory": "1Gi",
  "min_replicas": 1,
  "max_replicas": 1,
  "ingress_enabled": true,
  "external_enabled": false,
  "target_port": 5432,
  "ingress_transport": "tcp",
  "exposed_port": 5432,
  "needs_storage": true,
  "storage_mount_path": "/var/lib/postgresql/data",
  "storage_quota_gb": 20,
  "storage_access_mode": "ReadWrite",
  "env_vars": {
    "POSTGRES_DB": "mydb",
    "POSTGRES_USER": "myuser",
    "POSTGRES_PASSWORD": "mypassword"
  }
}

⁠Environment Variables

VariableDefaultDescription
POSTGRES_USERpostgresPostgreSQL superuser name
POSTGRES_PASSWORD(required)Password for the superuser
POSTGRES_DB$POSTGRES_USERDefault database to create
PGDATA/var/lib/postgresql/data/pgdataData directory path

⁠Features

  • Based on official postgres:16-alpine image
  • Automatic database initialization on first run
  • Configured for network access (listens on all interfaces)
  • Health check included
  • UTF-8 encoding and en_US locale
  • SCRAM-SHA-256 password authentication

⁠Building Locally

cd docker/postgres-azure
docker build -t postgres-azure:16 .

⁠Testing Locally

docker run -d \
  --name postgres-test \
  -e POSTGRES_USER=testuser \
  -e POSTGRES_PASSWORD=testpass \
  -e POSTGRES_DB=testdb \
  -p 5432:5432 \
  postgres-azure:16

# Test connection
psql -h localhost -U testuser -d testdb

Tag summary

Content type

Image

Digest

sha256:6eac07efd…

Size

19.3 MB

Last updated

5 months ago

docker pull aalhalim/postgres-azure