Published on

Run or build x86_64 Docker image on Apple M1, M2, and M3

Authors

When we run a docker image on an Apple laptop with a silicon chip (like M1, M2 or M3), by default it'll use the ARM64 architecture instead of x86_64 architecture.

This will cause issues when you try to run a docker image that is built for x86_64 architecture or on a platform that is not ARM64.

For example, if you try to build a AWS Lambda layer using docker image and try to use it in your AWS Lambda function with x86 architecture, you'll be facing some random issue in your dependency due to architecture mismatch.

Fixing it is pretty straightforward, you just need to add --platform linux/amd64 flag to your docker command.

docker run --platform linux/amd64 <image-name>

Similarly for building a docker image, you can use the same flag.

docker build --platform linux/amd64 -t <image-name> .

Note: x86_64/x86/amd64 are same names for 64-bit AMD/Intel CPUs. Similarly AArch64/arm64/ARMv8/ARMv9 are same names for 64-bit ARM CPUs.

Happy building and shipping 🎉