# Use a lightweight Python base image FROM python:3.11-slim # Set the working directory WORKDIR /api COPY . . # 系統套件多裝 execstack # 結論:是 onnxruntime 的 .so 要求可執行 stack,導致 import 直接掛、容器秒退。 RUN apt-get update && apt-get install -y \ # libgl1-mesa-glx \ libgl1 \ libglx-mesa0 \ libglib2.0-0 \ && rm -rf /var/lib/apt/lists/* # Install dependencies RUN pip install --no-cache-dir -r requirements.txt # 安裝 patchelf,用來清掉 onnxruntime .so 的 exec-stack 旗標 RUN apt-get update && apt-get install -y --no-install-recommends patchelf \ && rm -rf /var/lib/apt/lists/* #########2025/0923 update######### # 找到 onnxruntime 的 .so 並清除 exec-stack(沒有就略過) RUN set -eux; \ so="$(find /usr/local/lib/python* -path '*/site-packages/onnxruntime/capi/onnxruntime_pybind11_state*.so' -print -quit 2>/dev/null)"; \ if [ -n "$so" ]; then \ patchelf --print-execstack "$so" || true; \ patchelf --clear-execstack "$so" || true; \ patchelf --print-execstack "$so" || true; \ fi #########2025/0923 update######### # Expose the application's port EXPOSE 7860 # Start the FastAPI application CMD ["python","-m","uvicorn","app.main:app","--host","0.0.0.0","--port","7860"]