docker-copyedit icon indicating copy to clipboard operation
docker-copyedit copied to clipboard

Possible to alter arm64 images on amd64 machine?

Open dkebler opened this issue 2 years ago • 8 comments

Using moby buildkit and buildx bake I can build arm64 images on my amd64 machine. Is there a way to use your script to alter an arm64 image but doing so on a amd64 machine? I assume it would, like moby buildkit, have to do so in a dockerized arm64 container using qemu.

dkebler avatar May 23 '23 15:05 dkebler

The script is in python but it depends a few external tools like "docker" and "tar" to save an image to disk and to unpack that archive. The question is whether that docker save and load routines can be replaced by the tools that you use to manage the docker images. Note that "podman" was designed as a drop-in replacement for the "docker" client command and it still showed problems. So.... if you can figure out how to save/load an image archive then it should work.

gdraheim avatar May 23 '23 17:05 gdraheim

(no response)

gdraheim avatar Jun 12 '23 09:06 gdraheim

The question is whether that docker save and load routines can be replaced by the tools that you use to manage the docker images.

Last time I checked, there wasn't a way to save an image to disk with docker buildx.

q0rban avatar Jun 12 '23 15:06 q0rban

If you can see the buildx results in "docker images" then all should be fine. If it uses containerd directly then check "ctr images" where ctr has also import/export commands. That's my best guess.

gdraheim avatar Jun 12 '23 16:06 gdraheim

Okay, so I investigated this again. It is possible to save the built image to docker images with docker buildx using the --load option. The limitation for my use case is that it's not possible to build multi-platform images using the --load option. So, for the original requester, if you just want to build and alter an arm64 image on an amd64 machine, this is possible with buildx. However, I cannot figure out how to alter an arm64/amd64 (multi-platform) image. I can output a multi-platform in OCI format, but not docker image format. Or I can output individual images for each platform in docker image format, but I'm not sure if it's possible to then compile those distinct images into a single multi-platform image.

q0rban avatar Jul 04 '23 22:07 q0rban

The one way I've thought about altering a multiplatform image is to run a local registry and push the multiplatform image from buildx to there, then pull the image from the local registry, save it, make the alterations, and load it.

q0rban avatar Jul 04 '23 23:07 q0rban

One advantage to docker buildx, is that it seems that it's possible to skip the step of docker save by using --output type=docker,dest=- which outputs a docker image tarball:

docker buildx build --platform linux/arm64 --output type=docker,dest=- . | tar -C path/to/tmp -x
# perform alterations using manifest.json and config and then reload:
tar -C path/to/tmp -c . | docker load

q0rban avatar Jul 04 '23 23:07 q0rban

As of three weeks ago (and no simple way to do this) I opted to build my image from scratch instead of building from one with an unwanted VOLUME I then needed to remove using this tool. Still if I find another situation where I couldn't do that I'd revisit this. Thx anyway.

dkebler avatar Jul 05 '23 15:07 dkebler