Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

EverythingDevOps profile imageDivine Odazie
Divine Odazie forEverythingDevOps

Posted on • Originally published ateverythingdevops.dev

Building x86 Images on an Apple M1 Chip

This article was originally posted onEverything DevOps.

A few months ago, while deploying an application in Amazon Elastic Kubernetes Service (EKS), my pods crashed with astandard_init_linux.go:228: exec user process caused: exec format error error.

After a bit of research, I found out that the error tends to happen when the architecture an image is built on differs from the architecture it is running on. I then remembered that I was building the image on a MacBook with Apple M1 Chip which is based onARM64 architecture, and the worker nodes in the EKS cluster I deployed on are based onx86 architecture.

I had two options to fix the error: create new ARM-based worker nodes or build the image on x86 architecture. I couldn’t create new worker nodes for obvious reasons, so I had to figure out how to build x86 images on my Apple M1 chip.

In this article, I will walk you through how I built my application’s Docker image with x86 architecture on an Apple M1 chip usingDocker Buildx.

What is Docker Buildx?

Docker Buildx is a CLI plugin that extends the docker command. Docker Buildx provides the same user experience asdocker build with many new features like the ability to specify the target architecture for which Docker should build the image. These new features are made possible with the help of theMoby BuildKit builder toolkit.

Before you can build x86-64 images on an Apple M1 chip with Docker Buildx, you first need to install Docker Buildx.

Installing Docker Buildx

If you useDocker Desktop or have Docker version 20.x, Docker Buildx is already included in it, and you don’t need a separate installation. Verify that you have Docker Buildx with:

docker buildx version
Enter fullscreen modeExit fullscreen mode

But if you are like me that use another tool to get the Docker runtime, install Docker Buildx through the binary with the following commands:

$ ARCH=arm64$ VERSION=v0.8.2
Enter fullscreen modeExit fullscreen mode

The above commands set temporary environment variables for the architecture and version of the Docker Buildx binary you will download. See the Docker Buildxreleases page on GitHub for the latest version.

After setting the temporary environment variables, download the binary with:

$ curl -LO https://github.com/docker/buildx/releases/download/${VERSION}/buildx-${VERSION}.darwin-${ARCH}
Enter fullscreen modeExit fullscreen mode

After downloading the binary, create a folder in your home directory to hold Docker CLI plugins with:

$ mkdir -p ~/.docker/cli-plugins
Enter fullscreen modeExit fullscreen mode

Then move the binary to the Docker CLI plugins folder with:

$ mv buildx-${VERSION}.darwin-${ARCH} ~/.docker/cli-plugins/docker-buildx
Enter fullscreen modeExit fullscreen mode

After that, make the binary executable with:

$ chmod +x ~/.docker/cli-plugins/docker-buildx
Enter fullscreen modeExit fullscreen mode

To verify the installation, run:

$ docker buildx version
Enter fullscreen modeExit fullscreen mode

Building x86-64 images on an Apple M1 chip with Docker Buildx

After installing Docker Buildx, you can now easily build your application image to x86-64 on an Apple M1 chip with this command:

$ docker buildx build --platform=linux/amd64 -t <image-name> .
Enter fullscreen modeExit fullscreen mode

In the above command:

  • buildx builds the image using the BuildKit engine and does not require theDOCKER_BUILDKIT=1 environment variable to start the builds.
  • The--platform flag specifies the target architecture (platform) to build the image for. In this case,linux/amd64, which is of x86 architecture.
  • And the<image-name> is a placeholder for putting an image tag.

building the image with buildx

To verify that Docker built the image tolinux/amd64, use thedocker image inspect <image_name> command as you can see annotated screenshot above.

The inspect command will display detailed information about the image in JSON format. Scroll down, and you should see theArchitecture andOs information as in the image below.

Showing image architecture

Conclusion

This article explored building images based on x86 architecture on an Apple M1 chip using Docker Buildx. There is so much more to learn about Docker Buildx. To learn more, check out the following resources:

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

More fromEverythingDevOps

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp