#################### builder stage #################### FROM python:3.9-slim AS builder WORKDIR /build COPY requirements.txt . RUN pip install --prefix=/install -r requirements.txt COPY app.py . RUN python -m compileall -b -f app.py RUN tar -C /build -czf /build/app.tgz app.pyc #################### final stage #################### FROM python:3.9-slim WORKDIR /app # 1. Install dependencies COPY --from=builder /install /usr/local/ # 2. Copy the bytecode tarball into writable /tmp COPY --from=builder /build/app.tgz /tmp/app.tgz # 3. Add entrypoint COPY entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh EXPOSE 7860 ENTRYPOINT ["/entrypoint.sh"]