🐍
Docker Compose

Flask + PostgreSQL

Two-service compose stack — Flask API with PostgreSQL database (mid-point project pattern)

📋Configuration Files

docker-compose.yaml

PostgreSQL database + Flask app with env file and volume persistence

yaml
1version: "3.9"
2
3services:
4 db:
5 image: postgres:15-alpine
6 environment:
7 POSTGRES_DB: dukaan_db
8 POSTGRES_USER: dukaan
9 POSTGRES_PASSWORD: dukaan123
10 ports:
11 - "5432:5432"
12 volumes:
13 - pgdata:/var/lib/postgresql/data
14
15 app:
16 build: .
17 ports:
18 - "5000:5000"
19 env_file:
20 - .env
21 depends_on:
22 - db
23
24volumes:
25 pgdata:

Dockerfile

Flask application container image

dockerfile
1FROM python:3.12-slim
2WORKDIR /app
3COPY requirements.txt .
4RUN pip install --no-cache-dir -r requirements.txt
5COPY . .
6EXPOSE 5000
7CMD ["python", "app.py"]

Docker Compose → K8s: minimal vs production

What to add before production merge

AspectMinimalProduction
Networkingcompose default bridgeClusterIP + Ingress; no hostNetwork in prod
Secretsenv in compose fileK8s Secret + External Secrets; never plain YAML in git
Volumesbind mount ./dataPVC + backup strategy; StatefulSet for DB
Scalingreplicas: 1 in composeDeployment replicas + HPA; PDB for HA
Healthno healthcheckreadiness + liveness probes before Service traffic
Imagebuild: . locallypinned image from registry; CI builds digest
📄

Step 01

Run with Docker Compose

(01)Build and start services

Linux
1cd your-project/
2docker compose up -d --build
3docker compose ps
4docker compose logs -f app

(02)Stop and clean up

Linux
1docker compose down
2docker compose down -v # remove volumes