FROM python:3.11.15-bookworm
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update -y \
&& apt-get install -y --no-install-recommends \
libgl1-mesa-glx \
libx11-6 \
libxext6 \
libxrender1 \
tk \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Install Python dependencies first (cached layer)
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Copy the rest of the application code
COPY . .
# Default command to run the application (GUI)
CMD ["python","run.py"]
# Byte-size optimization and to avoid building context from local environment .git node_modules __pycache__ *.pyc *.pyo *.pyd venv *.egg-info .DS_Store media models
Concerns: The container runs as root; consider adding a non-root user for security., Smoke tests do not verify the actual GUI rendering in a headless environment; the app may fail when launched with a real display.
Smoke [FAIL]: test -f /app/run.py && echo 'run.py exists
Output: sh: 1: Syntax error: Unterminated quoted string
Smoke [FAIL]: python -c "import tkinter; print('tkinter OK')
Output: sh: 1: Syntax error: Unterminated quoted string
Smoke [PASS]: python -VFROM python:3.11.15-bookworm
ENV DEBIAN_FRONTEND=noninteractive
# Install system dependencies required for GUI and OpenCV
RUN apt-get update -y \
&& apt-get install -y --no-install-recommends \
libgl1-mesa-glx \
libx11-6 \
libxext6 \
libxrender1 \
tk \
&& rm -rf /var/lib/apt/lists/*
# Create a non-root user for security
RUN groupadd -r appuser && useradd -m -r -g appuser -d /home/appuser -s /bin/bash appuser
# Prepare working directory and set ownership to non-root user
WORKDIR /app
COPY --chown=appuser:appuser requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
# Copy the rest of the application code
COPY --chown=appuser:appuser . .
# Ensure the app directory is owned by the non-root user
RUN chown -R appuser:appuser /app
USER appuser
CMD ["python","run.py"]
Concerns: The app is a desktop GUI app; running in a headless container may fail when the GUI initializes unless a display/server is provided., The image installs system tkinter-related libraries (tk) but does not ensure the Python tkinter module is installed (often provided by python3-tk in Debian-based images). This could cause runtime import failures if the app relies on tkinter., Run-time behavior depends on run.py; if run.py requires a display or specific environment (e.g., X11, Wayland), the container may need additional configuration (e.g., X11 forwarding or a virtual display). Smoke [PASS]: python -V Smoke [PASS]: test -f /app/run.py Smoke [PASS]: python -m pip --version