hapifhir / hapi-fhir-jpaserver-starter

Apache License 2.0
390 stars 1.04k forks source link

Get docker to work on Apple silicon / M1 #313

Closed joeflack4 closed 9 months ago

joeflack4 commented 2 years ago

Description

When using a Macbook using an apple silicon / M1 CPU, docker-compose up -d --build fails.

Errors

1st error message

After doing mvn clean install, when doing docker-compose up -d --build, we got: no matching manifest for linux/arm64/v8 in the manifest list entries

2nd error message

After doing what's shown in "Thing's we've tried", we got: failed to solve: rpc error: code = Unknown desc = failed to solve with frontend dockerfile.v0: failed to create LLB definition: docker.io/hapiproject/hapi:base: not found

docker-compose up -d --build
...
⠿ f2e376ecd59f Pull complete 8.3s
[+] Building 0.5s (4/4) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 907B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> CANCELED [internal] load metadata for docker.io/library/tomcat:9-jre11 0.4s
=> ERROR [internal] load metadata for docker.io/hapiproject/hapi:base 0.4s
------
> [internal] load metadata for docker.io/hapiproject/hapi:base:
------
failed to solve: rpc error: code = Unknown desc = failed to solve with frontend dockerfile.v0: failed to create LLB definition: docker.io/hapiproject/hapi:base: not found

Things we've tried

We followed the instructions in this stackoverflow: https://stackoverflow.com/questions/69708866/how-to-make-docker-compose-work-on-m1-chip

It was suggested that we add the following to each of the services in the docker-compose.yml, so we did: platform: linux/x86_64

jkiddo commented 2 years ago

The image is currently only build for x86 - der https://hub.docker.com/r/hapiproject/hapi/tags

PR's for adding other archs as part of the GH action are welcome

chgl commented 2 years ago

Hm, it should build arm64 as well (https://github.com/hapifhir/hapi-fhir-jpaserver-starter/blob/master/.github/workflows/build-images.yaml#L15) it's also listed in the os/arch: https://hub.docker.com/layers/hapiproject/hapi/latest/images/sha256-4ce79b31a47b2be211405357ef433d2486aaf3e174fff3969172c5bf4b836400?context=explore

You could try replacing the 'build' part of the docket compose file by instead directly referencing the already build image. Ie instead of build: use image: docker.io/hapiproject/hapi:v5.6.0

jkiddo commented 2 years ago

@joeflack4 is it still not working for you?

joeflack4 commented 2 years ago

This wasn't an issue on my computer, but that of my colleague's: @Sigfried

@Sigfried: You probably don't have time for this, but if you do, do you want to see if chgl's suggestion works?

Daanoz commented 2 years ago

Hmm, it looks like all the base images don't have arm64 support.

bitnami/tomcat:

gcr.io/distroless/java17:nonroot:

Daanoz commented 2 years ago

Ok, based on the linked threads, I worked around the problem using the following in a Dockerfile:

FROM hapiproject/hapi:v6.0.1 as hapi

FROM gcr.io/distroless/java17-debian11:nonroot-$TARGETARCH as default
USER 65532:65532
WORKDIR /app

COPY --chown=nonroot:nonroot --from=hapi /app /app

CMD ["/app/main.war"]

(note: you need to use java17-debian11 and not java17)

patrick-werner commented 2 years ago

@jkiddo this works fine. What do you think about switching to java17-debian11 for the distroless build? For the debuggable image we could use: java17-debian11:debug, or switch to alpine. Both are supporting arm64.

What do you think?

jkiddo commented 2 years ago

Im fine with that. That is also what https://github.com/hapifhir/hapi-fhir-jpaserver-starter/pull/413 is about

Sigfried commented 2 years ago

This wasn't an issue on my computer, but that of my colleague's: @Sigfried

@Sigfried: You probably don't have time for this, but if you do, do you want to see if chgl's suggestion works?

Apologies for never testing that suggestion. I haven't worked on the project where this issue arose since February. But, if there's now a fix and someone wants me to test it, I can do that.