File size: 1,301 Bytes
5bf30ef dead143 5bf30ef dead143 5bf30ef dead143 5bf30ef 16c1df2 5bf30ef 16c1df2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | # 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"]
|