Cross-compiling Go Application Images with buildx

Overview

Driven by the need to cross-compile the image of an application I am developing privately (due to differences in architecture between the local development environment and the production environment), I implemented the solution and took notes.

buildx

Docker Desktop comes with buildx as a standard feature, so I used it.

Docker Buildx

With buildx, you can easily create multi-architecture compatible images.

Example

Let's say we have a Dockerfile like this (this is the actual Dockerfile I use):

For information on environment variables, refer to the link below. cf. https://matsuand.github.io/docs.docker.jp.onthefly/engine/reference/builder/

Building and pushing can be done as follows. You can specify multiple platforms.

Miscellaneous

The official MySQL image has, at some point, become compatible with ARM. This is great news for M1 users.

https://hub.docker.com/layers/library/mysql/8.0.29/images/sha256-44f98f4dd825a945d2a6a4b7b2f14127b5d07c5aaa07d9d232c2b58936fb76dc?context=explore

References