docker build --platform=linux/amd64 fails: ERROR: failed to solve: no match for platform in manifest

2 min read 21-10-2024
docker build --platform=linux/amd64 fails: ERROR: failed to solve: no match for platform in manifest


When using Docker, developers often encounter various errors during the build process. One common issue arises when you attempt to build an image for a specific platform using the command:

docker build --platform=linux/amd64 .

This command is intended to create a Docker image that runs on the linux/amd64 architecture. However, users may encounter the following error message:

ERROR: failed to solve: no match for platform in manifest

In this article, we will analyze this error, explore its causes, and provide solutions to help you resolve it effectively.

Understanding the Error

The error message "no match for platform in manifest" indicates that the Docker image you are trying to build does not have a suitable version available for the specified platform (linux/amd64). This can happen for a variety of reasons:

  1. Unsupported Architecture: The base image specified in your Dockerfile might not support the linux/amd64 architecture.
  2. Multi-Architecture Images: Some images are built with multi-architecture support, while others are not. If the image only supports ARM or another architecture, you will receive this error.
  3. Image Not Found: The image you are trying to pull may not exist in the repository or might be incorrectly named.
  4. Docker Desktop Settings: If you are using Docker Desktop, it may be configured to run on a different architecture by default.

Practical Solutions to Resolve the Error

To troubleshoot and resolve the "no match for platform in manifest" error, consider the following steps:

1. Verify the Base Image

Check the Dockerfile for the base image you are using. Confirm whether the image supports the linux/amd64 architecture. You can check the image documentation or Docker Hub page to see if it has a manifest list for the specified architecture.

Example:

If your Dockerfile starts with:

FROM arm64v8/alpine

You will need to switch it to an appropriate base image:

FROM amd64/alpine

2. Use a Multi-Architecture Image

If you need to build for multiple architectures, ensure you are using a multi-architecture image. You can build multi-arch images using Buildx, a Docker CLI plugin.

Example:

Set up and create a multi-architecture image:

docker buildx create --use
docker buildx build --platform linux/amd64,linux/arm64 -t my-image:latest .

3. Pull the Correct Image Version

If you are getting this error while trying to pull an image, you should ensure that you are pulling the correct version. You can specify the tag in your command to match the version compatible with your architecture:

docker pull my-image:latest

4. Adjust Docker Desktop Settings

If you are using Docker Desktop, you can verify the settings to ensure you are targeting the right architecture. Go to Settings > Experimental Features and check the "Use Rosetta for x86/amd64 emulation on Apple Silicon" option if you are on an M1/M2 Mac.

Additional Resources

Conclusion

The "no match for platform in manifest" error can be frustrating, but by understanding its causes and following the outlined solutions, you can effectively resolve the issue. Ensure you verify the base image, consider multi-architecture images, pull the correct versions, and check your Docker Desktop settings. By doing so, you'll have a smoother experience while building Docker images tailored for your desired platform.

By addressing these aspects, not only can you fix the error, but you can also enhance your knowledge and efficiency in using Docker. Happy Dockerizing!