Загрузка...

Cortex API Build 01 Lesson 07: Docker Compose FastAPI + Postgres Tutorial

Learn how to containerize a real FastAPI + PostgreSQL API using Docker & Docker Compose — no manual database setup required. In Cortex Build 01, Lesson 07, we turn everything you've been configuring by hand (Postgres install, passwords, database creation) into a single `docker compose up` command.
What you'll build
• Cortex document API — FastAPI backend with async PostgreSQL (asyncpg)
• Multi-service Docker Compose stack: Postgres 16 + Python API container
• Health checks, service dependencies, and volume-mounted seed data
• Paginated `/documents` endpoint with cursor-based pagination
• Idempotent data seeding that survives container restarts
🛠 Tech stack
FastAPI • Python 3.12 • PostgreSQL 16 • asyncpg • Docker • Docker Compose • uvicorn • pytest
📚 What this lesson covers
✅ Writing a production-style Dockerfile (layer caching, EXPOSE, CMD)
✅ docker-compose.yml with postgres + api services
✅ Healthcheck + depends_on: service_healthy pattern
✅ Applying a breaking API change deliberately (list → Page pagination)
✅ Fixing a real asyncpg event-loop bug (pool ownership in create_app)
✅ Seeding sample documents from the host via Docker volumes
✅ Testing with pytest (8/8 passing) and curl smoke tests
Quick start
git clone [your-repo-url]
cd build-01-lesson-07-code
chmod +x setup.sh && ./setup.sh
./start.sh
curl http://localhost:8888/health
WSL / Docker Desktop tip
If port 8000 is blocked on Windows, the API runs on port 8888. Use `./dev.sh` for local uvicorn + Docker Postgres on port 8000.
#FastAPI #DockerCompose #PostgreSQL #Python #BackendDevelopment #APITutorial #DockerTutorial #FullStack #DevOps #asyncpg #Microservices #WebDevelopment #LearnPython #Cortex

Видео Cortex API Build 01 Lesson 07: Docker Compose FastAPI + Postgres Tutorial канала Hands On Course Demo
Яндекс.Метрика
Все заметки Новая заметка Страницу в заметки
Страницу в закладки Мои закладки
На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.
О CookiesНапомнить позжеПринять