docker buildx multiarch from existing binaries

803 views Asked by At

based on pre compiled binaries i want to create a multiarch docker image. i created these binaries using https://github.com/cross-rs/cross .

i want to do something similar to:

FROM --PLATFORM=$TARGETPLATFORM ubuntu:20.04
ADD BINARY_$TARGETPLATFORM /BINARY

this approach does not work because it seems that $TARGETPLATFORM is not useable in "ADD".

build platform by platform and push all these platforms would be my favourite solution. All examples i found are building and pushing all platforms at the same time - which doesn't work for me, because i need to add the correct binary to every image.

it there a way to build platform by platform?

# seems that this is the buildx way
docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v . 

# i would like to to this:
cp target/linux/amd64/BINARY BINARY
docker buildx build --platform linux/amd64 . 
cp target/linux/arm64/BINARY BINARY
docker buildx build --platform linux/arm64 . 
cp target/linux/arm/BINARY BINARY
docker buildx build --platform linux/arm/v . 
docker buildx create_manifest_and_push_....

1

There are 1 answers

0
timg On

building multiple times and than creating a manifest was the solution for me.

cp target/x86_64-unknown-linux-musl/release/XXX XXX
docker buildx build --platform linux/amd64 -t XXX/XXX:latest_amd64 --push .
cp target/aarch64-unknown-linux-musl/release/XXX XXX
docker buildx build --platform linux/arm64 -t XXX/XXX:latest_arm64 --push .
docker manifest create XXX/XXX:latest XXX/XXX:latest_amd64 XXX/XXX:latest_arm64
docker manifest push XXX/XXX:latest