Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
When attempting to build a PHP image on MacOS, you might frequently run into the error: WARNING: The requested image's platform (linux/arm64) does not match the detected host platform (linux/amd64)
, and no specific platform was requested. This error message, which may appear in variations such as “the requested image platform linux amd64” or “warning image platform linux amd64 does not match the expected platform linux arm64” indicates a mismatch between the image and the host platform.
This error can be frustrating and impede the progress of your development. In this article, we’ll explore the causes of this error and how to resolve it by building the PHP image using Rosetta under the hood or from a Linux workstation instead of using MacOS.
Contents
When you try to build an image in Docker, it checks the host platform (in the case of MacOS, linux/amd64) and the platform of the requested image (linux/arm64). The error “the requested image platform linux amd64 does not match the detected host platform” occurs when there is an incompatibility between these platforms.
The error occurs when using docker run
, for example:
docker run --rm -p 9000:9000 1234567.dkr.ecr.us-east-1.amazonaws.com/devops-mind:php-1
Example of the error:
WARNING: The requested image's platform (linux/arm64) does not match the detected host platform (linux/amd64) and no specific platform was requested
standard_init_linux.go:337: exec user process caused: exec format error
Different architectures, such as amd64 and arm64, represent different instruction sets that processors use. Newer Macs with Apple Silicon chips (M1 and M2) use the arm64 architecture, while many Containers and images are built for amd64. This incompatibility can cause the error mentioned.
MacOS, especially on Apple Silicon machines, is not the most user-friendly platform for building Docker images that have not been optimized for arm64. The lack of native support can result in various problems, including the error the requested image platform linux amd64 / warning image platform linux amd64 does not match the expected platform linux arm64
and similar:
the requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
warning: the requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
the requested image's platform (linux/amd64) does not match the detected host platform
the requested image's platform (linux/amd64)
warning: image platform (linux/amd64) does not match the expected platform (linux/arm64)
and no specific platform was requested
the requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8)
warning: the requested image's platform (linux/amd64) does not match the detected host platform
warning: the requested image's platform (linux/arm64) does not match the detected host platform (linux/amd64/v3) and no specific platform was requested
image platform (linux/amd64) does not match the expected platform (linux/arm64)
the requested image platform linux amd64
warning image platform linux amd64 does not match the expected platform linux arm64
To solve this incompatibility problem, you can use Rosetta 2, a technology developed by Apple that allows x86 architectures to be emulated on ARM-based systems. You can run Docker applications and images built for amd64 architectures on a macOS host with an ARM CPU.
Here are the steps to use Rosetta 2 to resolve the “exec format error” error:
softwareupdate --install-rosetta
in the terminal.uname -m
, which should return “x86_64” even on a macOS ARM host.docker build
command to build the image, specifying the desired architecture with the --platform
option.docker build --platform linux/amd64 -t meu-container-php .
Run the Container amd64: You can now run the amd64 Container on your macOS ARM host without any problems, as Rosetta 2 will emulate your system’s x86_64 (amd64) architecture.
docker run -it meu-container-php
Rosetta 2 is an elegant and transparent solution for dealing with the architectural incompatibility between Docker images and macOS ARM hosts. It allows you to run amd64 applications and Containers on ARM systems without making changes to the code or the image.
To avoid the error the requested image platform linux amd64 does not match
, it is recommended to use a Linux workstation to build the PHP image. Linux has more robust support for different architectures, making compatibility easier.
docker --version
to make sure you have the correct version installed.{"experimental": true}
in the file /etc/docker/daemon.json
.With the Linux environment configured, you can proceed to build the PHP image.
Dockerfile
file with the following content:FROM php:7.4-cli
COPY . /usr/src/myapp
WORKDIR /usr/src/myapp
CMD [ "php", "./seu-script.php" ]
Dockerfile
is located.sh docker build -t my-php-app .
sh docker images
To ensure that the built image works correctly, run a Container from it:
sh docker run -it --rm my-php-app
The error “WARNING: The requested image’s platform (linux/arm64) does not match the detected host platform (linux/amd64) and no specific platform” is a common obstacle when building Docker images on MacOS, especially with the new Apple Silicon chips. However, by using Rosetta 2 or a Linux workstation to build your images, you can avoid this incompatibility and ensure that your applications work correctly and manages to avoid new occurrences of the requested image platform linux amd64 / warning image platform linux amd64 does not match the expected platform linux arm64
.
This approach solves the immediate problem and prepares your development environment for future builds of Containers, ensuring greater compatibility and efficiency.
If you found this article useful, be sure to check out our other content on Docker and development in PHP. Keep up to date with best practices and tips for optimizing your development workflow.
Be sure to subscribe to our newsletter to receive the latest news and tips about DevOps/SRE directly to your email:
Also check out this video about the platform issue when using Docker: