Skip to content

Goで実装したプログラムのコンテナイメージ化

This content is a draft and will not be included in production builds.

ko-build/ko が使えるなら、これがベストだと思う。

使えないのなら、—mount=type=bind でローカルのファイルシステムをマウントしつつ、—mount=type=cache でGoモジュールをキャッシュするといい。

# syntax=docker/dockerfile:1
FROM golang:1.23 AS builder
WORKDIR /go/src
RUN --mount=type=bind,target=. go build -o /go/bin/server
FROM gcr.io/distroless/static-debian12:nonroot-amd64 AS worker
COPY --from=builder /go/bin/server /var/runtime/bootstrap
ENTRYPOINT ["/var/runtime/bootstrap"]