Methods

Emulation

Using QEMU which is provided with Docker Desktop.

The image used in FROM must be available on the target platform.

Cross-compilation

Using image provided capabilities to cross-compile.

GOOS and GOARCH for Go build commandGo.

Use ARGs provided by Docker:

Set using --platform flag in build command.

  • BUILDPLATFORM - platform of the host running the build
  • BUILDOS - OS part of the BUILDPLATFORM
  • BUILDARCH - arch part of the BUILDPLATFORM
  • TARGETPLATFORM - target platform
  • TARGETOS - OS part of the TARGETPLATFORM
  • TARGETARCH - architecture part of the TARGETPLATFORM

Examples

go uses different Dockerfile for each arch/OS variant. See: docker library/golang

hello-world uses the same approach: docker-library/hello-world

References