'Docker on Mac M1 gives: "The requested image's platform (linux/amd64) does not match the detected host platform"
I want to run a docker container for Ganache
on my MacBook M1, but get the following error:
The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
After this line nothing else will happen anymore and the whole process is stuck, although the qemu-system-aarch64 is running on 100% CPU according to Activity Monitor until I press CTRL+C.
My docker-files come from this repository. After running into the same issues there I tried to isolate the root cause and came up with the smallest setup that will run into the same error.
This is the output of docker-compose up --build
:
Building ganache
Sending build context to Docker daemon 196.6kB
Step 1/17 : FROM trufflesuite/ganache-cli:v6.9.1
---> 40b011a5f8e5
Step 2/17 : LABEL Unlock <[email protected]>
---> Using cache
---> aad8a72dac4e
Step 3/17 : RUN apk add --no-cache git openssh bash
---> Using cache
---> 4ca6312438bd
Step 4/17 : RUN apk add --no-cache python python-dev py-pip build-base && pip install virtualenv
---> Using cache
---> 0be290f541ed
Step 5/17 : RUN npm install -g [email protected]
---> Using cache
---> d906d229a768
Step 6/17 : RUN npm install -g yarn
---> [Warning] The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
---> Running in 991c1d804fdf
docker-compose.yml:
version: '3.2'
services:
ganache:
restart: always
build:
context: ./development
dockerfile: ganache.dockerfile
env_file: ../.env.dev.local
ports:
- 8545:8545
ganache-standup:
image: ganache-standup
build:
context: ./development
dockerfile: ganache.dockerfile
env_file: ../.env.dev.local
entrypoint: ['node', '/standup/prepare-ganache-for-unlock.js']
depends_on:
- ganache
ganache.dockerfile:
The ganache.dockerfile can be found here.
Running the whole project on an older iMac with Intel-processor works fine.
Solution 1:[1]
If you're planning to run the image in your laptop, you need to build it for the cpu architecture of that particular machine. You can provide the --platform
option to docker build (or even to docker-compose
) to define the target platform you want to build the image for.
For example:
docker build --platform linux/amd64 .
Solution 2:[2]
On M1 MacBook Pro, I've had success using docker run --platform linux/amd64
Example
docker run --platform linux/amd64 node
Solution 3:[3]
With docker-compose you also have the platform
option.
version: "2.4"
services:
zookeeper:
image: confluentinc/cp-zookeeper:7.1.1
hostname: zookeeper
container_name: zookeeper
platform: linux/amd64
ports:
- "2181:2181"
Solution 4:[4]
You might need to run
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
in order to register foreign file formats with the kernel.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | TheFunSideofData |
Solution 2 | Ryan |
Solution 3 | Ryan |
Solution 4 | Thor Tomasarson |