Trung BìnhFastAPI iconFastAPI

FastAPI app trong Docker nên tối ưu gì?

Docker image nên dùng base image rõ version, cài dependency có cache tốt, không chạy bằng root nếu không cần, copy source sau dependency để tận dụng layer cache, và expose healthcheck endpoint.

Ví dụ command phổ biến:

CMD ["fastapi", "run", "app/main.py", "--port", "8000"]

Trong production nên cấu hình env vars, structured logs stdout/stderr, graceful shutdown, readiness/liveness probe và giới hạn CPU/memory từ orchestrator.

Xem toàn bộ FastAPI cùng filter theo level & chủ đề con.

Mở danh sách FastAPI