Dockerfile写作
FROM --platform=$BUILDPLATFORM golang:1.17-alpine AS build
WORKDIR /src
ARG TARGETOS TARGETARCH
RUN --mount=target=. \
--mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o /out/myapp .
FROM alpine
COPY --from=build /out/myapp /bin
执行命令:
docker buildx build --platform linux/amd64,linux/arm64 --push -t registry-shdocker-registry.cn-shanghai.cr.aliyuncs.com/wmj/test:v4.0-prod-20230314-1 -f Dockerfile .