Learn how to force Docker to build amd64 images on Apple M1 chips to avoid compatibility issues on common cloud platforms.
Using Docker images built on Apple's M1 chip - Apple Silicon chip to deploy with AMD64 architecture mechines such as Linux or Windows (AWS EC2, ECS, Alibaba Cloud Function Compute, etc.) will bring some issues. Therefore, in order to deploy the image built by Apple chips on the above platforms, we need to specify the image to build the AMD64 architecture.
There are several ways to achieve this:
Specify
DOCKER_DEFAULT_PLATFORMparameter in your environmentYou can run
export DOCKER_DEFAULT_PLATFORM=linux/amd64directly before building, or put this in your env config files, e.g..bashrc,.zshenvor.zshrcetc. by doing this will avoid setting it every time.Specify the platform in the From of the
DockerfileFor example
FROM --platform=linux/amd64 python:3.6If building with
docker-compose, you can specifypaltform: linux/amd64services: servername: platform: linux/amd64 ......
Reference source: https://stackoverflow.com/questions/65612411/forcing-docker-to-use-linux-amd64-platform-by-default-on-macos
I had so many questions while writing this—what’s your take?