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.
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.