Mac M1 芯片上的 Docker 映像构建失败

发布于 2025-01-11 02:55:07 字数 2529 浏览 0 评论 0原文

我正在尝试在 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.Provider

Caused 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

蓝海 2025-01-18 02:55:08

看起来 dockerfile-maven-plugin 使用基于 x86 架构的运行时,无法在 Apple M1 (Arm) 上运行。
该插件现在处于非活动状态,因此您应该尝试其他方法,例如 fabric8-maven-plugin

          <plugin>
            <groupId>io.fabric8</groupId>
            <artifactId>docker-maven-plugin</artifactId>
            <version>0.38.1</version>
            <executions>
                <execution>
                    <id>build</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>build</goal>
                    </goals>
                </execution>
            </executions>
        </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

          <plugin>
            <groupId>io.fabric8</groupId>
            <artifactId>docker-maven-plugin</artifactId>
            <version>0.38.1</version>
            <executions>
                <execution>
                    <id>build</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>build</goal>
                    </goals>
                </execution>
            </executions>
        </plugin> 
┊风居住的梦幻卍 2025-01-18 02:55:08

两个 Spotify docker maven 插件都不再维护。他们需要将其依赖项升级到支持 aarch64 的版本。

在我们的例子中,需要进行大量重构才能转移到fabric8的插件或使用maven exec,因此我们希望继续使用spotify插件。

幸运的是,您可以通过在插件部分添加 部分来强制插件使用特定的依赖项。

                <plugin>
                    <groupId>com.spotify</groupId>
                    <artifactId>dockerfile-maven-plugin</artifactId>
                    <version>1.4.6</version>
                    <dependencies>
                        <dependency>
                            <groupId>com.github.jnr</groupId>
                            <artifactId>jnr-unixsocket</artifactId>
                            <version>0.38.14</version>
                        </dependency>
                    </dependencies>
                </plugin>

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.

                <plugin>
                    <groupId>com.spotify</groupId>
                    <artifactId>dockerfile-maven-plugin</artifactId>
                    <version>1.4.6</version>
                    <dependencies>
                        <dependency>
                            <groupId>com.github.jnr</groupId>
                            <artifactId>jnr-unixsocket</artifactId>
                            <version>0.38.14</version>
                        </dependency>
                    </dependencies>
                </plugin>

治碍 2025-01-18 02:55:08

我遇到了同样的问题。根据错误信息,应该是与docker daemon的连接错误。看来该插件不支持Arm套接字,你可以这样做:

(1)​​安装socat

brew install socat

(2)设置端口转发

socat TCP-LISTEN:2375,range=127.0.0.1/32,reuseaddr,fork UNIX-CLIENT:/var/run/docker.sock

(3)设置环境变量

export DOCKER_HOST=tcp://127.0.0.1:2375

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

brew install socat

(2) set port forwarding

socat TCP-LISTEN:2375,range=127.0.0.1/32,reuseaddr,fork UNIX-CLIENT:/var/run/docker.sock

(3) set environment variable

export DOCKER_HOST=tcp://127.0.0.1:2375
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文