build: optimize Docker image and switch to production server
- Add --no-install-recommends flag to apt-get to reduce image size - Add ca-certificates package for secure HTTPS connections - Clean pip cache after installing dependencies (rm -rf /root/.cache/pip) - Replace Flask development server with Gunicorn for production deployment - Configure Gunicorn with 4 workers, 120s timeout, and access/error logging - Binding to 0.0.0.0:5001 for container networking
This commit is contained in:
13
Dockerfile
13
Dockerfile
@@ -1,7 +1,7 @@
|
||||
FROM python:3.11-slim
|
||||
|
||||
# Install system dependencies for Pillow and Tesseract
|
||||
RUN apt-get update && apt-get install -y \
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
tesseract-ocr \
|
||||
libtesseract-dev \
|
||||
libfreetype6-dev \
|
||||
@@ -18,7 +18,7 @@ RUN apt-get update && apt-get install -y \
|
||||
wget \
|
||||
unzip \
|
||||
git \
|
||||
&& fc-cache -f -v \
|
||||
ca-certificates \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Download and install select Google Fonts from GitHub
|
||||
@@ -60,8 +60,9 @@ WORKDIR /app
|
||||
# Copy requirements first for better caching
|
||||
COPY requirements.txt .
|
||||
|
||||
# Install Python dependencies
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
# Install Python dependencies and clear cache
|
||||
RUN pip install --no-cache-dir -r requirements.txt && \
|
||||
rm -rf /root/.cache/pip
|
||||
|
||||
# Copy application files
|
||||
COPY app.py .
|
||||
@@ -76,5 +77,5 @@ EXPOSE 5001
|
||||
# Set environment variables
|
||||
ENV PYTHONUNBUFFERED=1
|
||||
|
||||
# Run the application
|
||||
CMD ["python", "app.py"]
|
||||
# Run the application with Gunicorn
|
||||
CMD ["gunicorn", "--bind", "0.0.0.0:5001", "--workers", "4", "--timeout", "120", "--access-logfile", "-", "--error-logfile", "-", "app:app"]
|
||||
|
||||
Reference in New Issue
Block a user