x86 Build in M1 Mac


Building docker images with the flag --platform linux/amd64 allows you to create x86 images using docker

Which platform am I on?

> gcc -dumpmachine

Let’s run an image to enter the x86 world#

> docker run -it --platform=linux/amd64 gcc:13.2.0 /bin/bash
(inside docker container)> gcc -dumpmachine

When to use this?#

This is helpful to build cross platform images. i.e. in Elixir you can create a binary file with mix release however it only targets the current platform target triple. As my server runs on linux/amd64 I would have to build the code again rather than just copying over the binary file. Hence, I use this script to build the binary for the x86 platform and copy over the binary file only.