Dockerfile 1.24 KB
# Use Python 3.9 slim image
FROM python:3.9-slim

# Set working directory
WORKDIR /app

# Install system dependencies
RUN apt-get update && apt-get install -y \
    gcc \
    g++ \
    libgl1 \
    libglib2.0-0 \
    libsm6 \
    libxext6 \
    libxrender-dev \
    libgomp1 \
    curl \
    && rm -rf /var/lib/apt/lists/*

# Copy requirements first for better caching
COPY requirements-docker.txt .

# Install Python dependencies
# 使用国内镜像 + PyTorch官方CPU wheel链接,确保不安装CUDA版本
RUN pip install --no-cache-dir -r requirements-docker.txt \
    -i https://mirrors.aliyun.com/pypi/simple/ \
    --trusted-host mirrors.aliyun.com \
    --retries 5 \
    --timeout 300

# Copy application code
COPY . .

# Create necessary directories with proper permissions
RUN mkdir -p \
    data/uploads \
    data/design_images \
    data/logs \
    data/faiss \
    && chmod -R 755 data

# Create non-root user for security
RUN useradd -m -u 1000 appuser && \
    chown -R appuser:appuser /app

# Switch to non-root user
USER appuser

# Expose port
EXPOSE 5088

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
    CMD curl -f http://localhost:5088/health || exit 1

# Run the application
CMD ["python", "app.py"]