Intellij Idea 在Windows上通过Maven spring-boot:build-image构建docker镜像时,如何定义架构arm 64?

ds97pgxw  于 2023-03-29  发布在  Windows
关注(0)|答案(3)|浏览(359)

我在一个父节点中有几个Sping Boot 微服务,我可以运行spring-boot:build-image为所有模块构建Docker镜像。我使用Windows WSL 2 Ubuntu x86_64和Docker Engine通过IntelliJ中的配置构建镜像。
在我的Windows机器上一切都很好,我可以成功地启动容器,但我希望我的映像在我的Raspberry Pi Ubuntu Server 21.04 for architecture ARM 64的容器中运行,并通过我的Windows Docker注册表将它们拉出来,这样我就可以轻松地在本地传输映像。我的注册表工作正常,但随后我遇到了由于架构问题无法启动映像的错误。

如何在IntelliJ Maven配置运行中更改docker镜像构建的架构?

我发现通过Maven的Spring启动配置非常方便,它可以为构建映像进行各种配置。我不知道如何使用docker-composite.yml或Dockerfile来成功构建映像。如果这是答案,我将专注于我的研究,但到目前为止,我很困惑该怎么做。
我的想法是使用pom.xml并在那里定义任何配置。我的pom.xml现在看起来像这样:

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
  • 问题编辑 *:我看到你可以使用参数--platform=linux/arm64。我可以把它放在什么地方吗?
xytpbqjk

xytpbqjk1#

我已经找到了答案,直到现在,我还无法运行的事情之一-使用Dockerfile。
1.在IntelliJ中,我通过 Services 连接到本地网络上的Docker远程Raspberry Pi示例
1.我创建一个简单的Dockerfile

FROM openjdk:11
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","/app.jar"]

1.我在IntelliJ中选择Deploy on the Docker instance并选择Dockerfile
1.它现在在我的Raspberry Pi上构建和部署我的应用程序,而无需任何本地Windows服务
通过运行Deploy with IntelliJ的Dockerfile成功构建并部署了Docker镜像和容器!* 我很高兴 *

c9qzyr3d

c9qzyr3d2#

问题的解决方案不是在Maven构建步骤,而是在Docker构建步骤(在您进行Maven构建之后)。
我能够使用Maven spring-boot:build-image,然后使用这个Docker命令来构建ARM arch的镜像:
docker buildx build --platform linux/arm/v7 --tag <username>/<image name>:<tag> .
添加一个--push标志将在构建时自动将图像推送到注册表。

31moq8wy

31moq8wy3#

我是Docker和容器化的新手。我正在尝试将我的Sping Boot 应用程序Docker化,我使用了以下命令:spring-boot:build-image in IntelliJ Maven build config cmd arguments,在此之前一切都很好。但我突然发现我们可以在哪里运行这个命令:docker buildx build --platform linux/arm/v7 --tag <username>/<image name>:<tag> .
我真的很感激你的帮助!
下面是我POM供参考:

<build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <configuration>
                        <image>
                            <name>something/cloud-containers-${project.artifactId}:${project.version}</name>
                        </image>
                        <pullPolicy>IF_NOT_PRESENT</pullPolicy>
                    </configuration>
                </plugin>
            </plugins>
   </build>

相关问题