Force Docker to use AMD64 in Apple Silicon ( Apple M1 ) chips

avatar
Mofei Zhu

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:

  1. Specify DOCKER_DEFAULT_PLATFORM parameter in your environment

    You can run export DOCKER_DEFAULT_PLATFORM=linux/amd64 directly before building, or put this in your env config files, e.g. .bashrc, .zshenv or .zshrc etc. by doing this will avoid setting it every time.

  2. Specify the platform in the From of the Dockerfile

    For example

    FROM --platform=linux/amd64 python:3.6
  3. If building with docker-compose, you can specify paltform: linux/amd64

    services:
       servername:
         platform: linux/amd64
         ......
    

Reference source: https://stackoverflow.com/questions/65612411/forcing-docker-to-use-linux-amd64-platform-by-default-on-macos