-
-
Save ph1048/471686b1c58ee351e5c799cc044bdfb8 to your computer and use it in GitHub Desktop.
Example multi-arch Dockerfile for Go projects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.16 as builder | |
ARG TARGETPLATFORM | |
ARG BUILDPLATFORM | |
ARG TARGETOS | |
ARG TARGETARCH | |
WORKDIR /app/ | |
ADD . . | |
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="-w -s" -o yourapplication main.go | |
FROM --platform=${TARGETPLATFORM:-linux/amd64} scratch | |
WORKDIR /app/ | |
COPY --from=builder /app/yourapplication /app/yourapplication | |
ENTRYPOINT ["/app/yourapplication"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.DEFAULT_GOAL := default | |
IMAGE ?= yourapplication:latest | |
export DOCKER_CLI_EXPERIMENTAL=enabled | |
.PHONY: build # Build the container image | |
build: | |
@docker buildx create --use --name=crossplat --node=crossplat && \ | |
docker buildx build \ | |
--output "type=docker,push=false" \ | |
--tag $(IMAGE) \ | |
. | |
.PHONY: publish # Push the image to the remote registry | |
publish: | |
@docker buildx create --use --name=crossplat --node=crossplat && \ | |
docker buildx build \ | |
--platform linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x \ | |
--output "type=image,push=true" \ | |
--tag $(IMAGE) \ | |
. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment