2

I've been building some multiarch images for Java apps, based off someone else's multiarch base image which works fine, because the base image includes the right native Java version for the architecture. All I have to do is add my platform-agnostic JAR file and I have a multiarch image that works on my Windows laptop and on my rPi Kubernetes cluster.

Now though, I am experimenting with GraalVm and I would like to create a multiarch base image of my own that my projects will all use. This means I need to work out how to create a multiarch Docker image where different architectures require different installs. The amd64 Dockerfile needs the amd64 version of GraalVm to be installed and the arm Dockerfile needs the arm version of GraalVM.

I have used Dockerfile ARGs with --build-arg in the past to work out what URI to download for the GraalVm installer, but I am stuck on how to do this with 'buildx'.

It seems that every single demo/tutorial I watch uses a simple example where the files they add are not specific to the architecture. So they can just add them regardless of the platform being built for. How do people solve this problem? Is buildx not suitable for this problem?

The manifest approach seems much more appropriate for this problem (albeit more verbose) in that I can create an image for each architecture and then combine them, thus giving me the opportunity to build them differently. Is this just a constraint of the tooling? I'd rather do it with buildx if it can be done.

Peter
  • 13,733
  • 11
  • 75
  • 122
Ramsay Domloge
  • 695
  • 3
  • 11
  • I don't know buildx, but from general description it seems maybe multi-stage can be correct direction here. Did you try it? – RafaelJan May 04 '21 at 08:52
  • I've not tried that - perhaps you could elaborate? I guess I would need a stage for each platform which downloads the appropriate Binary for that platform? How would buildx know which stage to build with which builder? – Ramsay Domloge May 04 '21 at 13:17
  • The idea of multi-stage is to use one Dockerfile that can build several types of images according to the docker build command you use. You will create first stage that is common for all platform, and other stages that are for specific platforms. When you use this Dockerfile you will use the --target flag to specify which image type you want to build for example `docker build --target=amd64 -t image_amd64` or `docker build --target=arm -t image_arm` – RafaelJan May 04 '21 at 15:38
  • I don't think multi-stage images solve the problem (which I too have). Multi-stage builds require you to pass in the target, leaving you with a single-arch image. I can't find anything else, so I believe currently, we have to use the manifest approach. Unless you've found another way @RamsayDomloge? – Peter Aug 17 '22 at 13:46

0 Answers0