You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为何Chroma DB在python:3.10-slim容器中因非法指令崩溃?

问题:Chroma DB在Docker镜像中调用时因chroma-hnswlib触发SIGILL崩溃

环境背景

  • Python 3.10 + Flask REST API应用,集成Chroma DB 0.4.8
  • 应用在本地Windows/OS X开发机运行正常
  • 使用多阶段Dockerfile基于python:3.10-slim(Debian 12 Bookworm)构建镜像,通过Github Actions的google-github-actions/deploy-cloudrun@v1部署到Google Cloud Run

Dockerfile内容

FROM python:3.10-slim as base

ENV PYTHONFAULTHANDLER=1 \
    PYTHONHASHSEED=random \
    PYTHONUNBUFFERED=1

WORKDIR /app

# -------------------------------------

FROM base as builder

ENV PIP_DEFAULT_TIMEOUT=100 \
    PIP_DISABLE_PIP_VERSION_CHECK=1 \
    PIP_NO_CACHE_DIR=1 \
    POETRY_VERSION=1.6

RUN apt-get update --fix-missing && apt-get install -y --fix-missing build-essential

RUN pip install "poetry==$POETRY_VERSION"

COPY pyproject.toml ./

COPY chat_api ./chat_api
RUN poetry config virtualenvs.in-project true && \
    poetry install --only=main --no-root && \
    poetry build

# -------------------------------------

FROM base as final

COPY --from=builder /app/.venv ./.venv
COPY --from=builder /app/dist .
COPY docker-entrypoint.sh .
RUN ./.venv/bin/pip install *.whl
RUN ["chmod", "+x", "docker-entrypoint.sh"]

CMD ["./docker-entrypoint.sh"]

pyproject.toml依赖配置

[tool.poetry.dependencies]
python = "^3.10"
flask = "^2.3.3"
langchain = "^0.0.279"
flask-api = "^3.1"
openai = "0.27.8"
chromadb = "0.4.8"
tiktoken = "^0.4.0"
flask-sqlalchemy = "^3.0.5"
sqlalchemy = "^2.0.20"
pymysql = "^1.1.0"
google-cloud-logging = "^3.6.0"
flask-httpauth = "^4.8.0"
flask-cors = "^4.0.0"
gunicorn = "^21.2.0"
flask-migrate = "^4.0.4"
cryptography = "^41.0.3"

错误回溯信息

[ERROR] Worker (pid:3) was sent SIGILL!
Uncaught signal: 4, pid=3, tid=3, fault_addr=3.
Extension modules: google._upb._message, grpc._cython.cygrpc, charset_normalizer.md, _cffi_backend, markupsafe._speedups, sqlalchemy.cyextension.collections, sqlalchemy.cyextension.immutabledict, sqlalchemy.cyextension.processors, sqlalchemy.cyextension.resultproxy, sqlalchemy.cyextension.util, greenlet._greenlet, yaml._yaml, pydantic.typing, pydantic.errors, pydantic.version, pydantic.utils, pydantic.class_validators, pydantic.config, pydantic.color, pydantic.datetime_parse, pydantic.validators, pydantic.networks, pydantic.types, pydantic.json, pydantic.error_wrappers, pydantic.fields, pydantic.parse, pydantic.schema, pydantic.main, pydantic.dataclasses, pydantic.annotated_types, pydantic.decorator, pydantic.env_settings, pydantic.tools, pydantic, numpy.core._multiarray_umath, numpy.core._multiarray_tests, numpy.linalg._umath_linalg, numpy.fft._pocketfft_internal, numpy.random._common, numpy.random.bit_generator, numpy.random._bounded_integers, numpy.random._mt19937, numpy.random.mtrand, numpy.random._philox, numpy.random._pcg64, numpy.random._sfc64, numpy.random._generator, multidict._multidict, yarl._quoting_c, aiohttp._helpers, aiohttp._http_writer, aiohttp._http_parser, aiohttp._websocket, frozenlist._frozenlist, numexpr.interpreter (total: 56)
  File "/app/.venv/bin/gunicorn", line 8 in <module>
  File "/app/.venv/lib/python3.10/site-packages/gunicorn/app/wsgiapp.py", line 67 in run
  File "/app/.venv/lib/python3.10/site-packages/gunicorn/app/base.py", line 236 in run
  File "/app/.venv/lib/python3.10/site-packages/gunicorn/app/base.py", line 72 in run
  File "/app/.venv/lib/python3.10/site-packages/gunicorn/arbiter.py", line 202 in run
  File "/app/.venv/lib/python3.10/site-packages/gunicorn/arbiter.py", line 571 in manage_workers
  File "/app/.venv/lib/python3.10/site-packages/gunicorn/arbiter.py", line 642 in spawn_workers
  File "/app/.venv/lib/python3.10/site-packages/gunicorn/arbiter.py", line 609 in spawn_worker
  File "/app/.venv/lib/python3.10/site-packages/gunicorn/workers/base.py", line 142 in init_process
  File "/app/.venv/lib/python3.10/site-packages/gunicorn/workers/sync.py", line 126 in run
  File "/app/.venv/lib/python3.10/site-packages/gunicorn/workers/sync.py", line 70 in run_for_one
  File "/app/.venv/lib/python3.10/site-packages/gunicorn/workers/sync.py", line 32 in accept
  File "/app/.venv/lib/python3.10/site-packages/gunicorn/workers/sync.py", line 135 in handle
  File "/app/.venv/lib/python3.10/site-packages/gunicorn/workers/sync.py", line 178 in handle_request
  File "/app/.venv/lib/python3.10/site-packages/flask/app.py", line 2213 in __call__
  File "/app/.venv/lib/python3.10/site-packages/flask/app.py", line 2190 in wsgi_app
  File "/app/.venv/lib/python3.10/site-packages/flask/app.py", line 1484 in full_dispatch_request
  File "/app/.venv/lib/python3.10/site-packages/flask/app.py", line 1469 in dispatch_request
  File "/app/.venv/lib/python3.10/site-packages/flask_httpauth.py", line 174 in decorated
  File "/app/.venv/lib/python3.10/site-packages/redacted/routes.py", line 39 in messages_post
  File "/app/.venv/lib/python3.10/site-packages/redacted/logic.py", line 25 in __init__
  File "/app/.venv/lib/python3.10/site-packages/redacted/logic.py", line 40 in _load_vector_store
  File "/app/.venv/lib/python3.10/site-packages/langchain/vectorstores/chroma.py", line 119 in __init__
  File "/app/.venv/lib/python3.10/site-packages/chromadb/__init__.py", line 143 in Client
  File "/app/.venv/lib/python3.10/site-packages/chromadb/config.py", line 247 in instance
  File "/app/.venv/lib/python3.10/site-packages/chromadb/api/segment.py", line 82 in __init__
  File "/app/.venv/lib/python3.10/site-packages/chromadb/config.py", line 188 in require
  File "/app/.venv/lib/python3.10/site-packages/chromadb/config.py", line 244 in instance
  File "/app/.venv/lib/python3.10/site-packages/chromadb/config.py", line 293 in get_class
  File "/usr/local/lib/python3.10/importlib/__init__.py", line 126 in import_module
  File "<frozen importlib._bootstrap>", line 1050 in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027 in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688 in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883 in exec_module
  File "<frozen importlib._bootstrap>", line 241 in _call_with_frames_removed
  File "/app/.venv/lib/python3.10/site-packages/chromadb/segment/impl/manager/local.py", line 13 in <module>
  File "<frozen importlib._bootstrap>", line 1027 in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688 in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883 in exec_module
  File "<frozen importlib._bootstrap>", line 241 in _call_with_frames_removed
  File "/app/.venv/lib/python3.10/site-packages/chromadb/segment/impl/vector/local_persistent_hnsw.py", line 9 in <module>
  File "<frozen importlib._bootstrap>", line 1027 in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688 in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883 in exec_module
  File "<frozen importlib._bootstrap>", line 241 in _call_with_frames_removed
  File "/app/.venv/lib/python3.10/site-packages/chromadb/segment/impl/vector/local_hnsw.py", line 21 in <module>
  File "<frozen importlib._bootstrap>", line 1027 in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 674 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 571 in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 1176 in create_module
  File "<frozen importlib._bootstrap>", line 241 in _call_with_frames_removed
Current thread 0x00003ef4e1198b80 (most recent call first):
Fatal Python error: Illegal instruction

排查进展

  • 镜像虚拟环境中存在chroma_hnswlib-0.7.2.dist-info文件夹和hnswlib.cpython-310-x86_64-linux-gnu.so文件,但调用时仍崩溃
  • 更新1:改为单阶段Dockerfile,保留build-essential包在最终镜像中,本地AMD Ryzen 7机器运行镜像正常,但Google Cloud Run中崩溃依旧
  • 更新2:本地开发机构建镜像并直接部署到Cloud Run可正常运行,怀疑Github Actions构建时的CPU架构与Cloud Run不兼容

核心疑问

为何通过Github Actions构建的镜像无法在Cloud Run中正确运行chroma-hnswlib?该如何解决这个问题?

内容的提问来源于stack exchange,提问作者urig

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 13:32:03