Docker: image was found but does not match the specified platform (attempting to build amd64 on Apple M1)
Asked Answered
S

1

16

Disclaimer: I am new to Docker and am aware of my ignorance.

I am trying to build a Docker container with the amd64 architecture on computer with Apple's M1 Pro. I have specified platform: linux/amd64 in the docker-compose.yml as well as FROM --platform=linux/amd64 in the Dockerfile (both simultaneously and individually).

If I include it in the Dockerfile for that container, it builds fine but uname -a in that shell shows aarch64 architecture (not x86_64).

If I include it in docker-compose.yml, I get the following error:

Error response from daemon: image with reference api:latest was found but does not match the specified platform: wanted linux/amd64, actual: linux/arm64/v8

where api is one of the containers I am trying to build with docker-compose.

File Structure:

.
├── api
│   ├── Dockerfile-API
│   ├── entrypoint.sh
│   └── ...
├── db
│   └── ...
├── docker-compose.yml
└── nginx
    └── ...

./docker-compose.yml:

version: '3.0'
services:
  db:
    ...
  api:
    platform: linux/amd64 # line in question
    build:
      context: ./api
      dockerfile: Dockerfile-API
    command: ./run.sh
    depends_on:
      - db
    env_file: local.env
    networks:
      - nginx_network
    expose:
      - "8000"
    ports:
      - "3000:3000"
    image: api:latest
    ...
  nginx:
    ...

networks:
  nginx_network:
    external: true

volumes:
  ...

./api/Dockerfile-API

FROM --platform=linux/amd64 python3.6 # line in question
...

From directory . with platform set in docker-compose.yml:

$ docker-compose down
$ docker-compose up
Error response from daemon: image with reference api:latest was found but does not match the specified platform: wanted linux/amd64, actual: linux/arm64/v8

From directory . with platform set in ./api/Dockerfile-API:

$ docker-compose down
$ docker-compose up -d
$ docker-compose exec api bash
> uname -a
Linux bc17e565c265 5.10.104-linuxkit #1 SMP PREEMPT Thu Mar 17 17:05:54 UTC 2022 aarch64 GNU/Linux

I am grateful for any ideas/suggestions about why this is happening and how to fix it. Rosetta 2 is installed on my machine and Docker is up-to-date. Thank you!

Stylo answered 14/7, 2022 at 19:7 Comment(1)
Please provide a minimal reproducible example.Silvie
S
13

It turns out that docker-compose down is not equivalent with deleting an image. After deleting the api image through the Docker Desktop GUI then re-building (docker-compose up), I was able to create the container with x86_64 architecture.

Stylo answered 14/7, 2022 at 20:30 Comment(1)
You can also do up --build to force a re-build of the image, see docs.docker.com/engine/reference/commandline/compose_up/… — note that when not using docker-compose but just docker build, I had to add --no-cache to the options to force it to start from the AMD64 image.Whodunit

© 2022 - 2024 — McMap. All rights reserved.