Blogga qaytish
1-yanvar, 20245 min
Docker bilan Python: Production-ready Dockerfile
Multi-stage builds, security va optimization bilan ideal Dockerfile yaratish.
Docker bilan Python: Production-ready Dockerfile
Docker - zamonaviy deployment uchun standart. To'g'ri Dockerfile yozish muhim.
Multi-stage Build
``dockerfile
Build stage
FROM python:3.11-slim as builder
WORKDIR /app
COPY requirements.txt .
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /app/wheels -r requirements.txt
Production stage
FROM python:3.11-slim
WORKDIR /app
COPY --from=builder /app/wheels /wheels
RUN pip install --no-cache /wheels/*
COPY . .
CMD ["uvicorn", "main:app", "--host", "0.0.0.0"]
``
Security Tips
- Non-root user ishlatish
- Minimal base image tanlash
- Secrets ni environment variables orqali berish
Xulosa
To'g'ri Docker setup production uchun muhim. Image size va security ga e'tibor bering.
// Bu maqola foydali bo'ldi? Ulashing!