Building multi-architecture container images for AWS Graviton
What do my MacBook Pro and my container workload running on ECS and Fargate have in common? They both run amazingly well on the ARM processor architecture. However, building Docker images for Apple Silicon and AWS Graviton is challenging. Because a container image made for the
X86_64 architecture -which is good old Intel and AMD processors- does not run on the ARM processor architecture out of the box. Therefore, you will learn how to build multi-architecture images for
X86_64 as well as for
ARM64 in the following.
Watch the following video to learn how to build multi-architecture images locally and with AWS CodeBuild. Besides that, we will show you how to deploy a container image to ECS and Fargate running on
ARM64 (AWS Graviton).
You will find the commands and code snippets from the video in the following.
The commands and code snippets are excerpts of our book Rapid Docker on AWS which includes complete examples for PHP, Ruby, Python, Java, and Node.js web applications.
To build a multi-architecture image, start with creating an ECR repository.
aws ecr create-repository --repository-name nodejs-express
Next, create a new builder instance.
docker buildx create --use
docker buildx build command builds two container images, creates a manifest, and pushes all of that to the ECR repository.
docker buildx build \
To test the image on your local machine, use the
docker run command.
docker run 486555357186.dkr.ecr.eu-central-1.amazonaws.com/nodejs-express
That’s how to build a multi-architecture image locally. But how to do so as part of a CI/CD pipeline?
Looking for a new challenge?
The following snippets give you an idea of how to build a multi-architecture image with the help of AWS CodeBuild as part of a deployment pipeline.
The following snippet shows a CloudFormation resource to configure a CodeBuild project. Check out the comments for explanations.
buildspec.yml file is used to define the build job. The
aws/codebuild/standard:5.0 does not ship with the
buildx plugin. That’s why we need to add the plugin during the install phase.
Last but not least, the
build.sh script uses the same commands that we used to build a multi-architecture container image locally.
As you can now build multi-architecture images locally and with CodeBuild, one step is missing: deploying the image to ECS and Fargate.
The following snippet shows a CloudFormation template using cfn-modules to deploy an ECS service.
Unfortunately, the AWS Management Console does not show whether a container runs on
ARM64. Use the following AWS CLI command to fetch more detailed information about a task, including the processor architecture.
aws ecs describe-tasks --tasks 122e8587c57c43f38ae1c5618c656624 \
That’s it. Enjoy the power and efficiency of the ARM processor architecture!