(01)Build and start services
Linux
1cd your-project/2docker compose up -d --build3docker compose ps4docker compose logs -f appTwo-service compose stack — Flask API with PostgreSQL database (mid-point project pattern)
docker-compose.yaml
PostgreSQL database + Flask app with env file and volume persistence
1version: "3.9"2 3services:4 db:5 image: postgres:15-alpine6 environment:7 POSTGRES_DB: dukaan_db8 POSTGRES_USER: dukaan9 POSTGRES_PASSWORD: dukaan12310 ports:11 - "5432:5432"12 volumes:13 - pgdata:/var/lib/postgresql/data14 15 app:16 build: .17 ports:18 - "5000:5000"19 env_file:20 - .env21 depends_on:22 - db23 24volumes:25 pgdata:Dockerfile
Flask application container image
1FROM python:3.12-slim2WORKDIR /app3COPY requirements.txt .4RUN pip install --no-cache-dir -r requirements.txt5COPY . .6EXPOSE 50007CMD ["python", "app.py"]What to add before production merge
| Aspect | Minimal | Production |
|---|---|---|
| Networking | compose default bridge | ClusterIP + Ingress; no hostNetwork in prod |
| Secrets | env in compose file | K8s Secret + External Secrets; never plain YAML in git |
| Volumes | bind mount ./data | PVC + backup strategy; StatefulSet for DB |
| Scaling | replicas: 1 in compose | Deployment replicas + HPA; PDB for HA |
| Health | no healthcheck | readiness + liveness probes before Service traffic |
| Image | build: . locally | pinned image from registry; CI builds digest |
Step 01
1cd your-project/2docker compose up -d --build3docker compose ps4docker compose logs -f app1docker compose down2docker compose down -v # remove volumes