Mac M1 芯片上的 Docker 映像构建失败
我正在尝试在 Maven 项目内构建一个简单的 docker 映像,将映像构建添加为 Maven 构建过程的一部分:
<build>
<finalName>my-api</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- Docker -->
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.4.6</version>
<executions>
<execution>
<id>default</id>
<goals>
<goal>build</goal>
<!-- <goal>push</goal> -->
</goals>
</execution>
</executions>
<configuration>
<repository>reponame/${project.name}</repository>
<tag>${project.version}</tag>
<skipDockerInfo>true</skipDockerInfo>
</configuration>
</plugin>
</plugins>
</build>
FROM openjdk:8-jdk-alpine
VOLUME /tmp
EXPOSE 8080
ADD target/*.jar app.jar
ENTRYPOINT [ "sh", "-c", "java -jar /app.jar" ]
但它失败了,总是得到相同的错误跟踪,无论我使用哪个映像,错误仍然存在。
错误:
原因: com.spotify.docker.client.shaded.javax.ws.rs.ProcessingException: java.lang.UnsatisfiedLinkError:无法加载 FFI 提供程序 jnr.ffi.provider.jffi.Provider
引起:java.lang.UnsatisfiedLinkError: java.lang.UnsatisfiedLinkError: /private/var/folders/hz/rgppp8250rsdp86kf_tfjvqw0000gp/T/jffi8502916075702391528.dylib: dlopen(/私人/var/文件夹/hz/rgppp8250rsdp86kf_tfjvqw0000gp/T/jffi8502916075702391528.dylib, 0x0001):尝试过: '/私人/var/文件夹/hz/rgppp8250rsdp86kf_tfjvqw0000gp/T/jffi8502916075702391528.dylib' (胖文件,但缺少兼容的体系结构(有“i386,x86_64”, 需要'arm64e')),'/usr/lib/jffi8502916075702391528.dylib'(没有这样的 文件)
我尝试过的其他图像:
- openjdk:13-alpine3.9
- openjdk:8-jre-alpine3.9
- azul/zulu-openjdk-alpine:17.0.2-17.32.13-arm64
我的java版本 :openjdk 版本“11.0.13”2021-10-19 LTS
我的 Docker 版本:Docker版本 20.10.11,构建 dea9396
提前致谢。
I'm trying to build a simple docker image, inside a maven project, adding the image build as part of the maven build process:
<build>
<finalName>my-api</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- Docker -->
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.4.6</version>
<executions>
<execution>
<id>default</id>
<goals>
<goal>build</goal>
<!-- <goal>push</goal> -->
</goals>
</execution>
</executions>
<configuration>
<repository>reponame/${project.name}</repository>
<tag>${project.version}</tag>
<skipDockerInfo>true</skipDockerInfo>
</configuration>
</plugin>
</plugins>
</build>
FROM openjdk:8-jdk-alpine
VOLUME /tmp
EXPOSE 8080
ADD target/*.jar app.jar
ENTRYPOINT [ "sh", "-c", "java -jar /app.jar" ]
But it fails, always get the same error trace, no matter which image I use, the error persists.
Error:
Caused by:
com.spotify.docker.client.shaded.javax.ws.rs.ProcessingException:
java.lang.UnsatisfiedLinkError: could not load FFI provider
jnr.ffi.provider.jffi.ProviderCaused by: java.lang.UnsatisfiedLinkError:
java.lang.UnsatisfiedLinkError:
/private/var/folders/hz/rgppp8250rsdp86kf_tfjvqw0000gp/T/jffi8502916075702391528.dylib:
dlopen(/private/var/folders/hz/rgppp8250rsdp86kf_tfjvqw0000gp/T/jffi8502916075702391528.dylib,
0x0001): tried:
'/private/var/folders/hz/rgppp8250rsdp86kf_tfjvqw0000gp/T/jffi8502916075702391528.dylib'
(fat file, but missing compatible architecture (have 'i386,x86_64',
need 'arm64e')), '/usr/lib/jffi8502916075702391528.dylib' (no such
file)
Other images I tried:
- openjdk:13-alpine3.9
- openjdk:8-jre-alpine3.9
- azul/zulu-openjdk-alpine:17.0.2-17.32.13-arm64
My java version: openjdk version "11.0.13" 2021-10-19 LTS
My Docker version: Docker version 20.10.11, build dea9396
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看起来
dockerfile-maven-plugin
使用基于 x86 架构的运行时,无法在 Apple M1 (Arm) 上运行。该插件现在处于非活动状态,因此您应该尝试其他方法,例如 fabric8-maven-plugin
It looks like the
dockerfile-maven-plugin
uses a runtime based on x86 architecture and won't run on Apple M1 (Arm).The plugin is now inactive so you should try something else, for example the fabric8-maven-plugin
两个 Spotify docker maven 插件都不再维护。他们需要将其依赖项升级到支持 aarch64 的版本。
在我们的例子中,需要进行大量重构才能转移到fabric8的插件或使用maven exec,因此我们希望继续使用spotify插件。
幸运的是,您可以通过在插件部分添加
部分来强制插件使用特定的依赖项。Both of the spotify docker maven plugins are no longer maintained. They need to upgrade their dependency to a version that supports aarch64.
In our case there was significant refactoring needed to move to fabric8's plugin or to use maven exec so we wanted to continue to use spotify plugin.
Fortunately, you can force the plugin to use a particular dependency by adding a
<dependencies>
section to your plugin section.我遇到了同样的问题。根据错误信息,应该是与docker daemon的连接错误。看来该插件不支持Arm套接字,你可以这样做:
(1)安装socat
(2)设置端口转发
(3)设置环境变量
I met the same problem.According to the error message, it should be a connection error with the docker daemon.It seems that the plugin won't support Arm socket and you can do this:
(1) install socat
(2) set port forwarding
(3) set environment variable