From 82e7936d36d603a33e3d3d8d785e180ea6d074f6 Mon Sep 17 00:00:00 2001 From: Willem Jiang Date: Mon, 4 May 2026 09:41:10 +0800 Subject: [PATCH] fix(docker): set UTF-8 locale to prevent ASCII encoding errors in minimal containers (#2707) * fix(docker): set UTF-8 locale to prevent ASCII encoding errors in minimal containers * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- backend/Dockerfile | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/backend/Dockerfile b/backend/Dockerfile index c046268d3..dcb2f26e4 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -50,6 +50,12 @@ COPY backend ./backend RUN --mount=type=cache,target=/root/.cache/uv \ sh -c "cd backend && UV_INDEX_URL=${UV_INDEX_URL:-https://pypi.org/simple} uv sync ${UV_EXTRAS:+--extra $UV_EXTRAS}" +# UTF-8 locale prevents UnicodeEncodeError on Chinese/emoji content in minimal +# containers where locale configuration may be missing and the default encoding is not UTF-8. +ENV LANG=C.UTF-8 +ENV LC_ALL=C.UTF-8 +ENV PYTHONIOENCODING=utf-8 + # ── Stage 2: Dev ────────────────────────────────────────────────────────────── # Retains compiler toolchain from builder so startup-time `uv sync` can build # source distributions in development containers. @@ -66,6 +72,10 @@ CMD ["sh", "-c", "cd backend && PYTHONPATH=. uv run uvicorn app.gateway.app:app # Clean image without build-essential — reduces size (~200 MB) and attack surface. FROM python:3.12-slim-bookworm +ENV LANG=C.UTF-8 +ENV LC_ALL=C.UTF-8 +ENV PYTHONIOENCODING=utf-8 + # Copy Node.js runtime from builder (provides npx for MCP servers) COPY --from=builder /usr/bin/node /usr/bin/node COPY --from=builder /usr/lib/node_modules /usr/lib/node_modules