Multi-architecture container images for Amazon ECR
Some applications have specific host platform or operating system requirements, such as supporting both Linux and Windows. Docker images can support multiple architectures, which means that a single image may contain variants for different architectures, and sometimes for different operating systems, such as Windows.
In this article, we are describing how to create multi-architecture container image and pushing to Amazon ECR.
Docker Buildx is a CLI plugin that extends the docker command with the full support of the features provided by Moby BuildKit builder toolkit. It provides the same user experience as docker build with many new features like creating scoped builder instances and building against multiple nodes concurrently.
Dependency requirement in Jenkins
* Docker
* AWS CLI 2.X
Need to create buildX Profile
The default profile wont allow you to create multiple platform , so we need to create new buildX profile by providing following command in Jenkins machine
docker buildx create --name jenkinsBuildX
Use the newly created the profile for build x following command
docker buildx use jenkinsBuildX
Check the profile information
docker buildx inspect --bootstrap
Create a Dockerfile with following content
FROM ubuntu:20.04
Login to ECR repo via CLI
Private repo
aws ecr get-login-password — region us-west-2 | docker login — username AWS — password-stdin <<AccountID>>.dkr.ecr.us-west-2.amazonaws.comPublic repo
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws
Run following commands to generate multi-architecture image and push to ECR
docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t public.ecr.aws/ALIAS_ID/MyBaseREPO:Ubuntu-20.04 --push .