fastapi_celery/Dockerfile
2025-12-25 16:43:26 +08:00

38 lines
984 B
Docker

# Use Python 3.11 slim image
FROM python:3.11-slim
# Set environment variables
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1
# Set Aliyun mirrors for apt
RUN sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list.d/debian.sources && \
sed -i 's/security.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list.d/debian.sources
# Install system dependencies
RUN apt-get update && apt-get install -y \
curl \
build-essential \
&& rm -rf /var/lib/apt/lists/*
# Install uv using pip with Aliyun mirror
RUN pip install --no-cache-dir -i https://mirrors.aliyun.com/pypi/simple/ uv
# Set work directory
WORKDIR /app
# Copy pyproject.toml
COPY pyproject.toml ./
# Install Python dependencies using uv with Aliyun mirror
RUN uv sync --frozen --no-install-project
# Copy application code
COPY app/ ./app/
COPY main.py ./
# Expose port
EXPOSE 8000
# Run the application
CMD ["uv", "run", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]