Skip to content

Commit 3f5ffc2

Browse files
jkyberneeesclaude
andcommitted
fix(docker): build llama-mtmd-cli from source to fix glibc ABI mismatch
Pre-built Ubuntu release binaries for llama.cpp require GLIBC_2.38 / GLIBCXX_3.4.32, but Debian Bookworm ships glibc 2.36 / GLIBCXX_3.4.30, causing "missing shared library" failures at runtime. Fix: compile llama-mtmd-cli from source inside the same debian:bookworm-slim base as the runtime stage, with BUILD_SHARED_LIBS=OFF (statically links llama's internal libs) and GGML_OPENMP=OFF (no libgomp dependency, mirrors the whisper stage). The resulting binary depends only on standard Bookworm system libraries which are present in the runtime image. Also adds --retry-all-errors to the model download curl commands so transient CDN drops (curl error 18: partial file) are automatically retried. Locally tested: ldd shows only libstdc++/libm/libgcc_s/libc; live inference against a test image produces a correct description. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 7a8f539 commit 3f5ffc2

2 files changed

Lines changed: 24 additions & 27 deletions

File tree

docker/Dockerfile

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,13 @@ RUN mkdir -p /models \
5555
"https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-${WHISPER_MODEL}.bin"
5656

5757
# ---- minicpm-v stage ----
58-
# Downloads a pre-built llama-mtmd-cli binary and fetches MiniCPM-V 4.6 model
59-
# files (main GGUF + vision projector) so the `vision` tool works out of the
60-
# box with zero host setup. Pre-built binaries from the official llama.cpp
61-
# release avoid a multi-minute C++ compile inside Docker.
58+
# Builds llama-mtmd-cli from source (same Debian Bookworm base as the runtime
59+
# stage) so the binary links against the exact glibc/libstdc++ versions that
60+
# are present at runtime — no ABI mismatch. Pre-built Ubuntu release binaries
61+
# require GLIBC_2.38 / GLIBCXX_3.4.32, which Bookworm doesn't ship.
62+
# BUILD_SHARED_LIBS=OFF statically links llama's internal libraries so only
63+
# system libs (glibc, libstdc++) are needed at runtime.
64+
# GGML_OPENMP=OFF removes the libgomp dependency (mirrors the whisper stage).
6265
#
6366
# Size added to the runtime image: ~530 MB model + ~1.1 GB mmproj ≈ 1.6 GB.
6467
# To use a different quantization level: --build-arg MINICPM_QUANT=Q8_0
@@ -68,31 +71,28 @@ FROM debian:bookworm-slim AS minicpm
6871
ARG MINICPM_QUANT=Q4_K_M
6972
ARG LLAMA_VERSION=b9549
7073
RUN apt-get update && apt-get install -y --no-install-recommends \
71-
curl ca-certificates \
74+
git cmake make g++ curl ca-certificates \
7275
&& rm -rf /var/lib/apt/lists/*
73-
# Map dpkg architecture to the llama.cpp release asset name suffix
74-
# (amd64 → x64, arm64 → arm64). Extract the CLI binary and all bundled
75-
# shared libraries (.so*) — the pre-built Ubuntu binaries are dynamically
76-
# linked against libllama.so, libmtmd.so, etc. shipped in the same tarball.
77-
RUN set -ex \
78-
&& LLAMA_ARCH=$(dpkg --print-architecture | sed 's/amd64/x64/') \
79-
&& curl -fsSL \
80-
"https://github.com/ggerganov/llama.cpp/releases/download/${LLAMA_VERSION}/llama-${LLAMA_VERSION}-bin-ubuntu-${LLAMA_ARCH}.tar.gz" \
81-
-o /tmp/llama.tar.gz \
82-
&& mkdir -p /tmp/llama-bin \
83-
&& tar -xzf /tmp/llama.tar.gz -C /tmp/llama-bin \
84-
&& find /tmp/llama-bin -name "llama-mtmd-cli" -exec install -m 755 {} /usr/local/bin/llama-mtmd-cli \; \
85-
&& mkdir -p /usr/local/lib/llama \
86-
&& find /tmp/llama-bin -name "*.so*" -exec cp -P {} /usr/local/lib/llama/ \; \
87-
&& rm -rf /tmp/llama.tar.gz /tmp/llama-bin
76+
RUN git clone --depth 1 --branch "${LLAMA_VERSION}" \
77+
https://github.com/ggerganov/llama.cpp /llama \
78+
&& cmake -S /llama -B /llama/build \
79+
-DCMAKE_BUILD_TYPE=Release \
80+
-DBUILD_SHARED_LIBS=OFF \
81+
-DGGML_NATIVE=OFF \
82+
-DGGML_OPENMP=OFF \
83+
-DLLAMA_CURL=OFF \
84+
-DLLAMA_BUILD_TESTS=OFF \
85+
&& cmake --build /llama/build -j"$(nproc)" --target llama-mtmd-cli \
86+
&& install -m 755 /llama/build/bin/llama-mtmd-cli /usr/local/bin/llama-mtmd-cli \
87+
&& rm -rf /llama
8888
# Fetch the model GGUF and vision projector into a fixed image path (NOT under
8989
# ~/.odek — bind-mount profiles would hide files baked there). The runtime
9090
# config points vision.models_dir at this path, or the tool auto-detects it.
9191
RUN mkdir -p /usr/local/share/minicpm-v/models \
92-
&& curl -fsSL \
92+
&& curl -fSL --retry 5 --retry-delay 5 --retry-connrefused --retry-all-errors \
9393
"https://huggingface.co/openbmb/MiniCPM-V-4_6-gguf/resolve/78e02f066e9819a60573b78a4275df8a0c27f698/MiniCPM-V-4_6-${MINICPM_QUANT}.gguf" \
9494
-o /usr/local/share/minicpm-v/models/model.gguf \
95-
&& curl -fsSL \
95+
&& curl -fSL --retry 5 --retry-delay 5 --retry-connrefused --retry-all-errors \
9696
"https://huggingface.co/openbmb/MiniCPM-V-4_6-gguf/resolve/78e02f066e9819a60573b78a4275df8a0c27f698/mmproj-model-f16.gguf" \
9797
-o /usr/local/share/minicpm-v/models/mmproj.gguf
9898

@@ -126,12 +126,9 @@ COPY --from=whisper /models/ /usr/local/share/whisper/models/
126126

127127
# Bundle llama-mtmd-cli + MiniCPM-V 4.6 from the minicpm stage so `vision`
128128
# works with zero setup. The tool auto-detects /usr/local/share/minicpm-v/models.
129-
# The shared libraries (libllama.so, libmtmd.so, …) are registered via ldconfig
130-
# so the dynamically-linked binary resolves them at runtime.
129+
# Built from source with BUILD_SHARED_LIBS=OFF so only system libs are needed.
131130
COPY --from=minicpm /usr/local/bin/llama-mtmd-cli /usr/local/bin/llama-mtmd-cli
132-
COPY --from=minicpm /usr/local/lib/llama/ /usr/local/lib/llama/
133131
COPY --from=minicpm /usr/local/share/minicpm-v/models/ /usr/local/share/minicpm-v/models/
134-
RUN echo "/usr/local/lib/llama" > /etc/ld.so.conf.d/llama.conf && ldconfig
135132

136133
# ── Adding extra dependencies the agent can use ──────────────────────────
137134
# The agent runs shell commands INSIDE this image, so any runtime or CLI it

docker/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ auto-transcription work with zero setup. No host install, no first-run download.
152152

153153
## Image & video understanding (out of the box)
154154

155-
The image **bundles `llama-mtmd-cli` (llama.cpp b9549) and MiniCPM-V 4.6**
155+
The image **bundles `llama-mtmd-cli` (llama.cpp b9549, built from source) and MiniCPM-V 4.6**
156156
(1.3B multimodal model) so the `vision` tool works with zero setup — no cloud
157157
API, no host install, no first-run download.
158158

0 commit comments

Comments
 (0)