Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix(docker): copy only runtime artifacts into the final image (#30243)

yuneng-jiang1fd8ab4c5f72
diff --git a/Dockerfile b/Dockerfile
index 9ad9ab31b65..4d55148ff89 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -68,22 +68,24 @@ FROM $LITELLM_RUNTIME_IMAGE AS runtime
USER root
-RUN apk add --no-cache bash openssl tzdata nodejs npm python3 libsndfile && \
- GLOBAL="$(npm root -g)" && \
- for pkg in tar glob @isaacs/brace-expansion brace-expansion minimatch diff picomatch; do \
- name="${pkg##*/}"; \
- find "$GLOBAL/npm" -type d -name "$name" -path "*/node_modules/$pkg" | while read d; do \
- rm -rf "$d" && cp -rL "$GLOBAL/$pkg" "$d"; \
- done; \
- done && \
- npm cache clean --force && \
- { apk del --no-cache npm 2>/dev/null || true; }
+# node (without npm) is required by the prisma CLI at runtime
+RUN apk add --no-cache bash openssl tzdata nodejs python3 libsndfile
WORKDIR /app
ENV PATH="/app/.venv/bin:${PATH}"
-COPY --from=builder /app /app
+# Copy only what runtime needs. The application is installed inside the venv;
+# the rest of the builder's /app is source and build metadata that must not
+# ship (manifest-scanning tools attribute everything in it to this image).
+# entrypoint.sh invokes litellm/proxy/prisma_migration.py by source path.
+COPY --from=builder /app/.venv /app/.venv
+COPY --from=builder /app/docker /app/docker
+COPY --from=builder /app/schema.prisma /app/schema.prisma
+COPY --from=builder /app/litellm/proxy/prisma_migration.py /app/litellm/proxy/prisma_migration.py
+# enterprise/ is imported by source path at runtime (proxy_cli puts the
+# working directory on sys.path; litellm/proxy/hooks resolves
+# enterprise.enterprise_hooks from it)
+COPY --from=builder /app/enterprise /app/enterprise
# Prisma binaries live in $HOME/.cache (default prisma-python location),
# which is /root/.cache here. Copy only the Prisma subdirs — copying the
# whole /root/.cache drags in the uv build cache (~660 MB, includes a
diff --git a/docker/Dockerfile.database b/docker/Dockerfile.database
index c84003a065f..e591a4a2adb 100644
--- a/docker/Dockerfile.database
+++ b/docker/Dockerfile.database
@@ -66,36 +66,31 @@ FROM $LITELLM_RUNTIME_IMAGE AS runtime
USER root
-RUN apk add --no-cache bash openssl tzdata nodejs npm python3 libsndfile && \
- GLOBAL="$(npm root -g)" && \
- find "$GLOBAL/npm" -type d -name "tar" -path "*/node_modules/tar" | while read d; do \
- rm -rf "$d" && cp -rL "$GLOBAL/tar" "$d"; \
- done && \
- find "$GLOBAL/npm" -type d -name "glob" -path "*/node_modules/glob" | while read d; do \
- rm -rf "$d" && cp -rL "$GLOBAL/glob" "$d"; \
- done && \
- find "$GLOBAL/npm" -type d -name "brace-expansion" -path "*/node_modules/@isaacs/brace-expansion" | while read d; do \
- rm -rf "$d" && cp -rL "$GLOBAL/@isaacs/brace-expansion" "$d"; \
- done && \
- find "$GLOBAL/npm" -type d -name "minimatch" -path "*/node_modules/minimatch" | while read d; do \
- rm -rf "$d" && cp -rL "$GLOBAL/minimatch" "$d"; \
- done && \
- find "$GLOBAL/npm" -type d -name "diff" -path "*/node_modules/diff" | while read d; do \
- rm -rf "$d" && cp -rL "$GLOBAL/diff" "$d"; \
- done && \
- npm cache clean --force && \
- { apk del --no-cache npm 2>/dev/null || true; }
+# node (without npm) is required by the prisma CLI at runtime
+RUN apk add --no-cache bash openssl tzdata nodejs python3 libsndfile
WORKDIR /app
ENV PATH="/app/.venv/bin:${PATH}"
-COPY --from=builder /app /app
+# Copy only what runtime needs. The application is installed inside the venv;
+# the rest of the builder's /app is source and build metadata that must not
+# ship (manifest-scanning tools attribute everything in it to this image).
+# entrypoint.sh invokes litellm/proxy/prisma_migration.py by source path.
+COPY --from=builder /app/.venv /app/.venv
+COPY --from=builder /app/docker /app/docker
+COPY --from=builder /app/schema.prisma /app/schema.prisma
+COPY --from=builder /app/litellm/proxy/prisma_migration.py /app/litellm/proxy/prisma_migration.py
+# enterprise/ is imported by source path at runtime (proxy_cli puts the
+# working directory on sys.path; litellm/proxy/hooks resolves
+# enterprise.enterprise_hooks from it)
+COPY --from=builder /app/enterprise /app/enterprise
# Prisma binaries live in $HOME/.cache (default prisma-python location),
# which is /root/.cache here. Copy them from the builder so they survive
# deployments that volume-mount /app/.cache (e.g. readOnlyRootFilesystem
# + emptyDir) — otherwise the mount would shadow the baked-in query engine.
-COPY --from=builder /root/.cache /root/.cache
+# Only the Prisma subdirs: the whole /root/.cache drags in the uv build cache.
+COPY --from=builder /root/.cache/prisma /root/.cache/prisma
+COPY --from=builder /root/.cache/prisma-python /root/.cache/prisma-python
RUN find /app/.venv -type f -path "*/tornado/test/*" -delete && \
find /app/.venv -type d -path "*/tornado/test" -delete
diff --git a/docker/Dockerfile.non_root b/docker/Dockerfile.non_root
index 8717e5b3fcd..eafbd23fd90 100644
--- a/docker/Dockerfile.non_root
+++ b/docker/Dockerfile.non_root
@@ -95,7 +95,21 @@ RUN for i in 1 2 3; do \
apk add --no-cache python3 bash openssl tzdata libsndfile nodejs && break || sleep 5; \
done
-COPY --from=builder /app /app
+# Copy only what runtime needs. The application is installed inside the venv;
+# the rest of the builder's /app is source and build metadata that must not
+# ship (manifest-scanning tools attribute everything in it to this image).
+# entrypoint.sh invokes litellm/proxy/prisma_migration.py by source path.
+# Prisma caches live under /app/.cache here (XDG_CACHE_HOME /
+# PRISMA_BINARY_CACHE_DIR) so the runtime prisma generate finds them.
+COPY --from=builder /app/.venv /app/.venv
+COPY --from=builder /app/docker /app/docker
+COPY --from=builder /app/schema.prisma /app/schema.prisma
+COPY --from=builder /app/litellm/proxy/prisma_migration.py /app/litellm/proxy/prisma_migration.py
+# enterprise/ is imported by source path at runtime (proxy_cli puts the
+# working directory on sys.path; litellm/proxy/hooks resolves
+# enterprise.enterprise_hooks from it)
+COPY --from=builder /app/enterprise /app/enterprise
+COPY --from=builder /app/.cache /app/.cache
COPY --from=builder /var/lib/litellm/ui /var/lib/litellm/ui
COPY --from=builder /var/lib/litellm/assets /var/lib/litellm/assets