# syntax=docker/dockerfile:1 # Headless knox node: CLI + MCP stdio + gossip sync, one static binary. # # docker build -t docker.notsosm.art/knox:latest . # # The image runs as UID 1000 and keeps all state in /data (SQLite index, TLS # material, anything else you mount). modernc.org/sqlite is pure Go, so the # build needs no cgo and the runtime needs no toolchain. FROM golang:1.27-alpine AS build WORKDIR /src # Dependencies first so source edits do not invalidate the module layer. COPY go.mod go.sum ./ RUN --mount=type=cache,target=/go/pkg/mod \ --mount=type=cache,target=/root/.cache/go-build \ go mod download COPY . . # Cache mounts persist on the build daemon across builds, so a go.sum change no # longer forces a full re-download and rebuild of every dependency. RUN --mount=type=cache,target=/go/pkg/mod \ --mount=type=cache,target=/root/.cache/go-build \ CGO_ENABLED=0 go build -trimpath -ldflags='-s -w' -o /out/knox . FROM alpine:3.22 RUN apk add --no-cache ca-certificates \ && adduser -D -u 1000 -h /home/knox knox \ && mkdir -p /data && chown knox:knox /data COPY --from=build /out/knox /usr/local/bin/knox USER knox WORKDIR /home/knox # Persisted state: index.db (SQLite), tls/{cert,key}.pem. VOLUME ["/data"] ENV KNOX_DB=/data/index.db # 8931 gossip/REST, 8932 Prometheus metrics. EXPOSE 8931 8932 ENTRYPOINT ["knox"] CMD ["watch"]