Monday, August 28, 2023

How to Build Multi-platform Docker Images with Docker Buildx (Linux ARM64/AMD64)



Have you ever wished you could effortlessly build and deploy your applications across different platforms? Well, get ready to unlock the power of Docker Buildx and take your development game to the next level!
 
The stage is set for the main event – let's build that Docker image using the docker buildx build command. Here's what's happening in the spotlight:

the syntax:
docker buildx create --use --platform=linux/arm64,linux/amd64 --name multi-platform-builder
docker buildx inspect --bootstrap
docker buildx build --platform=linux/arm64,linux/amd64 --push --tag project-name:latest -f ./project-name/Dockerfile .
The --platform flag: Just like before, specify the platforms you're targeting. 
The --push flag: This is where the real magic happens. Your masterpiece will be pushed to a container registry, spreading your creation far and wide. 
The --tag flag: Give your creation a name – how about "project-name:latest"? 
The -f flag: Direct Docker to your building instructions, the almighty Dockerfile. In this case, it's chilling at "./project-name/Dockerfile". 
The final ".": This is your build context – the core files that shape your image's soul.

real world example:
# build multiple arch
docker buildx create --use --platform=linux/arm64,linux/amd64 --name infraunnes/php
docker buildx build --push --platform linux/arm64,linux/amd64 --tag infraunnes/php:8.1-apache .

0 comments:

Post a Comment