微信图片_20210414104152.jpg

FROM golang:1.13.0-stretch AS builder

ENV GO111MODULE=on \
    CGO_ENABLED=1

WORKDIR /build
COPY go.mod .
COPY go.sum .
RUN Go mod download
COPY . .
RUN Go build ./cmd/my-awesome-go-program
WORKDIR /dist
RUN cp /build/my-awesome-go-program ./my-awesome-go-program
RUN ldd my-awesome-go-program | tr -s '[:blank:]' '\n' | grep '^/' | \
    xargs -I % sh -c 'mkdir -p $(dirname ./%); cp % ./%;'
RUN mkdir -p lib64 && cp /lib64/ld-linux-x86-64.so.2 lib64/
RUN mkdir /data

# 构建最小运行时镜像
FROM scratch
COPY --chown=0:0 --from=builder /dist /
# User ID 65534 通常是 'nobody' 用户.
COPY --chown=65534:0 --from=builder /data /data
USER 65534
WORKDIR /data

ENTRYPOINT ["/my-awesome-go-program"]

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

Captcha Code