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 X86_64
and ARM64
(AWS Graviton).
You will find the commands and code snippets from the video in the following.
How to build a multi-architecture Docker image
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 |
The following 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?
How to build a multi-arch container image with AWS CodeBuild
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.
Project: |
The 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.
version: '0.2' |
Last but not least, the build.sh
script uses the same commands that we used to build a multi-architecture container image locally.
!/bin/bash |
As you can now build multi-architecture images locally and with CodeBuild, one step is missing: deploying the image to ECS and Fargate.
How to run X86_64 and ARM64 container images on ECS and Fargate
The following snippet shows a CloudFormation template using cfn-modules to deploy an ECS service.
AppService: |
Unfortunately, the AWS Management Console does not show whether a container runs on X86_64
or 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!
Further reading
- Article Terraform, can you keep a secret?
- Article Security Iceberg: AWS Security Hub the right way
- Article How to set up Jenkins on AWS?
- Tag container
- Tag fargate