# Use an official Python runtime as a parent image FROM python:3.9-slim # Set environment variables to ensure Python output is unbuffered (helps with logging) ENV PYTHONUNBUFFERED=1 # Install system dependencies that might be needed by Pillow or other libraries # gcc and python3-dev are for compiling C extensions if wheels are not available # libjpeg-dev, zlib1g-dev are common for Pillow's JPEG and PNG support # build-essential includes gcc, g++, make, etc. RUN apt-get update && apt-get install -y --no-install-recommends --fix-missing \ build-essential \ python3-dev \ libjpeg-dev \ zlib1g-dev \ && echo "System dependencies installed." \ && rm -rf /var/lib/apt/lists/* # Set the working directory in the container WORKDIR /app # Copy the requirements file first to leverage Docker cache COPY requirements.txt . # Install any needed packages specified in requirements.txt # Using --verbose can sometimes give more insight into pip errors RUN echo "Starting pip install..." && \ pip install --no-cache-dir --upgrade pip && \ pip install --no-cache-dir --verbose -r requirements.txt && \ echo "Pip install completed." # Copy all files from the build context (app.py, etc.) into the working directory COPY . . # Create necessary directories that the app will use # These directories will be relative to WORKDIR (/app) RUN echo "Creating directories: ./data ./downloads ./session" && \ mkdir -p ./data ./downloads ./session && \ echo "Setting permissions for directories..." && \ chmod -R 777 ./data ./downloads ./session && \ echo "Permissions set." # List contents of /app for debugging (check build logs for this output) RUN echo "Contents of /app:" && ls -la /app # Command to run the application when the container launches # The -u flag for python is equivalent to PYTHONUNBUFFERED=1 CMD ["python", "-u", "app.py"]