Closed joshlong closed 3 years ago
We use JNA for socket-based communication with the Docker daemon and, unfortunately, JNA does not yet support the M1 architecture (aarch64). https://github.com/java-native-access/jna/pull/1238 is tracking that. In the meantime, running the JVM on Rosetta or using a custom build of JNA that supports aarch64 (apparently there's one bundled in IntelliJ IDEA) are your two options.
Oh. that's a bummer :( thanks for the prompt reply in the meantime.
I'm so close to M1 goodness end to end
With thanks to @bsideup for reminding me, there is, of course, a third option. You can connect to the Docker daemon over TCP rather than via a domain socket. Setting DOCKER_HOST
to a tcp://
URL should be sufficient.
Note:
By default, Docker does not expose the TCP socket, and it is a bit tricky to do it on Mac.
But one can use Socat to re-expose the unix socket on a TCP port:
$ socat TCP-L:2375,fork UNIX:/var/run/docker.sock
$ export DOCKER_HOST=tcp://localhost:2375
$ http $DOCKER_HOST/containers/json
HTTP/1.1 200 OK
Api-Version: 1.41
Content-Type: application/json
Date: Sun, 24 Jan 2021 21:22:07 GMT
Docker-Experimental: true
Ostype: linux
Server: Docker/20.10.1 (linux)
Transfer-Encoding: chunked
[]
Note:
By default, Docker does not expose the TCP socket, and it is a bit tricky to do it on Mac.
But one can use Socat to re-expose the unix socket on a TCP port:
$ socat TCP-L:2375,fork UNIX:/var/run/docker.sock $ export DOCKER_HOST=localhost:2375 $ http $DOCKER_HOST/containers/json HTTP/1.1 200 OK Api-Version: 1.41 Content-Type: application/json Date: Sun, 24 Jan 2021 21:22:07 GMT Docker-Experimental: true Ostype: linux Server: Docker/20.10.1 (linux) Transfer-Encoding: chunked []
I had this issue in MacBook Air M1. The socat re-expose works for me.
I set the DOCKER_HOST=localhost:2375
first, but it didn't help. I used DOCKER_HOST=http://localhost:2375
instead. This fixed the issue.
@tsimashevich thanks! I updated the snippet. Also, JNA supports M1 since 5.7.0, so this issue should be gone now :)
@tsimashevich thanks! I updated the snippet. Also, JNA supports M1 since 5.7.0, so this issue should be gone now :)
I tried the latest release and still getting the issue. Will the next release fix the issue? Thanks!
@codewitch We upgraded to JNA 5.7.0 with Spring Boot 2.5.0-M3 (See https://github.com/spring-projects/spring-boot/issues/25424). Unfortunately nobody on the team has an M1 Mac so we can't say for sure if it fixed things.
I have a M1 Mac and can share my experience within spring-cloud-kubernetes
. There are a few internal projects where we exercise integration tests, see here. This is for example what I do for one of the modules:
mvn spring-boot:build-image -Dspring-boot.build-image.imageName=docker.io/springcloud/spring-cloud-kubernetes-client-config-it:2.1.0-SNAPSHOT -Dspring-boot.build-image.builder=paketobuildpacks/builder
This builds just fine and creates a proper docker image. Running it though requires an extra flag : --platform linux/arm64
docker run -p 8080:8080 springcloud/spring-cloud-kubernetes-client-config-it:2.1.0-SNAPSHOT --platform linux/arm64
and then curl localhost:8080/mySecret
gives the desired output.
@wind57 for me your suggestion produces:
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.4.3:build-image (default-cli) on project springworx: Execution default-cli of goal org.springframework.boot:spring-boot-maven-plugin:2.4.3:build-image failed: An API incompatibility was encountered while executing org.springframework.boot:spring-boot-maven-plugin:2.4.3:build-image: java.lang.UnsatisfiedLinkError: /Users/gmuth/Library/Caches/JNA/temp/jna17002984056587716793.tmp: dlopen(/Users/gmuth/Library/Caches/JNA/temp/jna17002984056587716793.tmp, 0x0001): tried: '/Users/gmuth/Library/Caches/JNA/temp/jna17002984056587716793.tmp' (fat file, but missing compatible architecture (have 'i386,x86_64', need 'arm64e')), '/usr/lib/jna17002984056587716793.tmp' (no such file)
@onesail this is something pretty recent, I've faced it too. I've upgraded to 2.6.2
iirc, for the maven plugin and all was good.
Thanks for pointing to version 2.6.2 of the spring-boot-maven-plugin! This is a step forward concerning the build tooling now at least running on M1 without a workaround.
Paketo BellSoft Liberica Buildpack 9.0.2
https://github.com/paketo-buildpacks/bellsoft-liberica
...
BellSoft Liberica JRE 11.0.13: Contributing to layer
Downloading from https://github.com/bell-sw/Liberica/releases/download/11.0.13+8/bellsoft-jre11.0.13+8-linux-amd64.tar.gz
What I still miss is the architecture parameter (list) to define which target architectures the images should be build for. The default architecture amd64
is not what I want. For native Apple Silicon (and Graviton2) support arm64
is required. I guess I have to stick with the jib plugin which supports build images for multiple platforms.
I am using M1. But I've got the error as follows:
22.42 [ERROR] Failed to execute goal on project qrcode-generator: Could not resolve dependencies for project id.my.hendisantika:qrcode-generator:jar:0.0.1: The following artifacts could not be resolved: org.springframework.boot:spring-boot-starter-logging:jar:3.2.1 (absent), org.apache.logging.log4j:log4j-to-slf4j:jar:2.21.1 (absent): Could not transfer artifact org.springframework.boot:spring-boot-starter-logging:jar:3.2.1 from/to central (https://repo.maven.apache.org/maven2): Remote host terminated the handshake: SSL peer shut down incorrectly -> [Help 1]
22.42 [ERROR]
22.42 [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
22.42 [ERROR] Re-run Maven using the -X switch to enable full debug logging.
22.42 [ERROR]
22.42 [ERROR] For more information about the errors and possible solutions, please read the following articles:
22.42 [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
------
Dockerfile:9
--------------------
7 | WORKDIR /project
8 |
9 | >>> RUN mvn clean package
10 |
11 | #FROM adoptopenjdk/openjdk21:eclipse-temurin-21-alpine
--------------------
ERROR: failed to solve: process "/bin/sh -c mvn clean package" did not complete successfully: exit code: 1
View build details: docker-desktop://dashboard/build/desktop-linux/desktop-linux/nqczctd1kdds4ccttpqufwxrn
Here is my Dockerfile
FROM maven:3.9.6-eclipse-temurin-21-alpine AS build
RUN mkdir /project
COPY . /project
WORKDIR /project
RUN mvn clean package
#FROM adoptopenjdk/openjdk21:eclipse-temurin-21-alpine
#FROM bellsoft/liberica-openjdk-debian:21
#FROM openjdk:21-slim
FROM amazoncorretto:21-alpine-jdk
LABEL maintainer="hendisantika@yahoo.co.id"
RUN mkdir /app
RUN addgroup -g 1001 -S hendigroup
RUN adduser -S hendi -u 1001
COPY --from=build /project/target/qrcode-generator-0.0.1.jar /app/qr.jar
WORKDIR /app
RUN chown -R hendi:hendigroup /app
CMD java $JAVA_OPTS -jar qr.jar
Here is my repo link: https://github.com/hendisantika/spring-boot-qrcode-generator
@hendisantika If you are using a Dockerfile and docker build
then you are not using the Spring Boot build plugins to build the image (for example, using mvn spring-boot:build-image
). This issue was related to using that Spring Boot support on an M1 machine, so your problem is different than this one.
It appears that the process in the Docker container is having problems with the network when downloading the project dependencies. Your Dockerfile works fine for me, so I suspect it is a problem with your local environment. If you continue to have problems, please post a question to Stack Overflow.
I tried with mvn clean spring-boot:build-image
OK.
Yes, Sorry @scottfrederick
Hi, and happy new year!
I have one of those new Apple Silicon M1 laptops. I was trying to use it to create a Docker image using
spring-boot:build-image
with the also very new and still-in-preview Docker Desktop. I got the error reproduced below.