Files
Memoh/docker/Dockerfile.mcp
T
Menci 8ce5243eb3 fix(mcp): use dumb-init as PID 1 to reap zombie processes
MCP containers spawning child processes (npx, uvx, etc.) left zombies
because the Go binary running as PID 1 does not reap orphaned children.
Add dumb-init as the entrypoint init process.
2026-03-09 12:41:23 +08:00

44 lines
1.4 KiB
Docker

# syntax=docker/dockerfile:1
FROM scratch AS gomodcache
FROM --platform=$BUILDPLATFORM golang:1.25-alpine AS build
WORKDIR /src
COPY go.mod go.sum ./
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=bind,from=gomodcache,target=/tmp/gomodcache \
set -eux; \
if [ -d /tmp/gomodcache/cache/download ]; then \
cp -a /tmp/gomodcache/. /go/pkg/mod/; \
fi; \
go mod download
COPY . .
ARG TARGETARCH
ARG COMMIT_HASH=unknown
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH:-amd64} \
go build -trimpath -ldflags "-s -w -X github.com/memohai/memoh/internal/version.CommitHash=${COMMIT_HASH}" -o /out/mcp ./cmd/mcp
FROM alpine:latest
# Base utilities
RUN apk add --no-cache grep curl bash dumb-init
# Node.js + npm (provides npx for JS/TS MCP servers)
RUN apk add --no-cache nodejs npm
# Python 3 + uv (provides uvx for Python MCP servers)
RUN apk add --no-cache python3 && \
curl -LsSf https://astral.sh/uv/install.sh | sh && \
ln -sf /root/.local/bin/uv /usr/local/bin/uv && \
ln -sf /root/.local/bin/uvx /usr/local/bin/uvx
WORKDIR /app
COPY --from=build /out/mcp /opt/mcp
COPY cmd/mcp/template /opt/mcp-template
COPY cmd/mcp/entrypoint.sh /opt/entrypoint.sh
RUN chmod +x /opt/entrypoint.sh
ENTRYPOINT ["/usr/bin/dumb-init", "--", "/opt/entrypoint.sh"]