Building docker images for x86_64 with an Apple Silicon CPU.
If you have a Mac and you deploy your applications with docker, there is the possibility you get this error
The requested image's platform (Linux/arm64/v8) does not match the detected host platform (linux/amd64/v4) and no specific platform was requested.
This is because you have an Apple Silicon CPU and the server that will run your image is based on a more traditional amd64/x86_64 architecture. For this, you will need to create an image that supports that type of CPU.
To achieve this, in docker you have the command
buildx build wich allows you to create images for different architectures, even to make it compatible with multiple architectures.
The use of this command is very simple. Returning to our initial scenario. If you are a Mac user with Apple Silicon CPU, just run:
docker buildx build --platform linux/amd64 -t myimage:tag .
linux/amd64 is the destination architecture for your image.
That's it, it was very simple, right? if you want to learn more about this command, here is the official documentation.
Did you know about this command before?
Share in the comments if it was useful to you.
Thanks for reading.