Docker image runs on Intel mac but not M1 mac
Asked Answered
K

5

8

We have a Java Spring Boot application that runs in a Docker container. It is based on openjdk:13-jdk-alpine. We deploy it to Linux machines, but we are also able to run it locally on Windows machines, as well as on an Intel-based iMac.

We have found, though, that it cannot run properly on an ARM-based MacBook Pro. The exceptions we get are basic Java errors like "Can't find symbol Java.class[]," and other things that look like the JVM is off.

Is there a way to build a Docker image that will work on all these platforms, including the M1 MacBook Pro?

Kilmarnock answered 29/8, 2021 at 18:17 Comment(6)
If this is your base image, then you are out of luck. The image is only available for amd64 architecture, not for ARM.Hourihan
Why do you deploy with a jdk and not jre, though? It increases your size for no reason at allKorman
@Korman That's a great point, and we will address that. But it wouldn't have any impact on the issue, I assume.Kilmarnock
@Hourihan Is there a JRE/Linux image that would work for both architectures? I just ran into an article about multi-arch images. Would that do the trick?Kilmarnock
Right, my point is that you could most probably deploy with any jre up to 15, cause in the 16 when module system started deprecated things and this might break things for your application.Korman
couldnt find any arm based openjdk image tagged as 13-jdk-* or 13-jre-*, if @Korman is correct maybe use a newer image, though you could anyway use this image hub.docker.com/r/adoptopenjdk/openjdk13/…Mongeau
F
7

I made it work with the following image. I pulled the image with

docker pull bellsoft/liberica-openjdk-alpine-musl:17

My Dockerfile:

FROM bellsoft/liberica-openjdk-alpine-musl:17
ADD build/libs/app-0.0.1-SNAPSHOT-plain.jar app.jar
ENTRYPOINT ["java","-jar","app.jar"]

Now the docker build command worked

Fausta answered 3/1, 2022 at 1:24 Comment(2)
It is working fine for meLux
not for me: 17: Pulling from bellsoft/liberica-openjdk-alpine-musl no matching manifest for darwin/arm64/v8 in the manifest list entriesPizzicato
B
2

I have a lot of problems with Java containers too on my M1 macbook. For your problem, maybe you need to create your own docker image:

Dockerfile

FROM --platform=linux/arm64/v8 ubuntu:20.04

ARG DEBIAN_FRONTEND=noninteractive
EXPOSE 8080

RUN apt update \
    && apt upgrade -y \
    && apt install -y openjdk-13-jre git \
    && apt clean

RUN mkdir -pv /app && cd /app && \
    git clone https://github.com/spring-guides/gs-spring-boot.git && \
    cd /app/gs-spring-boot/initial && ./gradlew build

WORKDIR /app/gs-spring-boot/initial

ENTRYPOINT [ "./gradlew", "bootRun" ]

Build image

docker build -t test .

Run container

docker run --rm -p 8080:8080 test

Go to http://localhost:8080/ on your browser and your Spring-Boot application is running without Rosetta 2.

Disclaimer: I'm not a Java developer and my Dockerfile is for Proof of Concept purpose.

Remember that your Docker image is builded to ARM64 architecture. If you wanna run this container on a Intel/AMD processor, you have to change FROM --platform=linux/amd64 ubuntu:20.04 on your Dockerfile.

Basilica answered 31/8, 2021 at 2:34 Comment(0)
I
0

Build your images with multiarch support to get rid of all possible architecture failures in the future. To do this cleanly, avoid using anything related to the platform in your Dockerfile, just old-school Dockerfiles are ok.

If you are using github and github-actions, you may check this to build your images and push them into your image repository. This can be also used for building images which work on RaspberryPi like SBCs.

Irritability answered 5/11, 2021 at 12:58 Comment(0)
J
0

it's because image is not supported for m1 yet, you can build it for cross platform and run it

docker build --platform=linux/arm64 -t image:latest .
Jameson answered 4/10, 2022 at 6:38 Comment(0)
M
0

remplace the image you have with this

FROM openjdk:17-jdk-slim-buster
Morelos answered 18/1 at 20:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.