dockerdockerfiledocker-imagebuildx

Questions about multi-arch docker image as base image in Dockerfile of project


I would like to use openjdk:15-alpine image as the base image for the Dockerfile of my java project (because it is lightweighted). But it only supports amd64 CPU architecture while I am using Macbook M2 chip which is armv64 architecture.

Here is the Dockerfile of my project, as you can see the base image is openjdk:15-alpine :

FROM openjdk:15-alpine

...

...

ENTRYPOINT ["java","-jar","/myapp.jar"]

EXPOSE 8080

I have two questions:

Q1. Is it so that if I want to build multi-arch image for my project, the base image itself has to be already multi-arch supported?

Q2. If the answer of above question is "yes", how can I build my own version of jdk:15-alpine that supports multi architecture (linux/amd64,linux/arm64), which I can then used as a base image of my Dockerfile?


Solution

  • Q1: yes, that is true. For example, for java, how would the AMD64 binaries in that image work on ARM64?

    Q2: by taking the original Dockerfile and building it on an ARM machine. Alternatively, you can also use BuildKit to build ARM images on AMD.