'How do I define architecture arm64 when building the docker image through Maven spring-boot:build-image on Windows?
I have several Spring Boot microservices in one parent and I can run spring-boot:build-image
to build docker images for all modules. I'm using my Windows WSL2 Ubuntu x86_64 and Docker Engine to build the images through the configuration in IntelliJ.
I'ts all fine and dandy on my Windows machine and I can start the containers successfull, but I want my images to run in containers on my Raspberry Pi Ubuntu Server 21.04 for architecture ARM64 and pull them through my Windows Docker Registry so I can easily transfer images locally. My registry works as well, but then I'm stuck with the error that the image cannot be started due to architecture problems.
How can I change the architecture of the docker image build in the IntelliJ Maven configuration run?
I've found the spring-boot configuration through Maven very convenient, it does all sorts of configuration for building the image. I don't know how to use docker-compose.yml or a Dockerfile to successfull build an image. If this is the answer I will focus my research on this, but up until now I'm quite stuck what to do.
My feeling goes towards the pom.xml and define any configuration there. My pom.xml looks like this right now:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Question edit:
I have seen you can use the parameter --platform=linux/arm64
. Can I put this somewhere?
Solution 1:[1]
I have found the answer to be one of the things I could not get running yet, until now - using a Dockerfile.
- In IntelliJ I connect to my Docker remote Raspberry Pi instance on my local network through Services
- I create a simple Dockerfile
FROM openjdk:11
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","/app.jar"]
- I choose Deploy on the Docker instance in IntelliJ and select the Dockerfile
- It now builds and deploys my application on my Raspberry Pi without any local Windows services coming inbetween
Successfully build and deployed a Docker image and container through the Dockerfile running Deploy with IntelliJ! I'm so happy
Solution 2:[2]
The solution to your problem isn't at the Maven build step but rather the Docker build step (which happens after you do a Maven build).
I was able to use Maven spring-boot:build-image
followed by this Docker command to build an image for ARM arch:
docker buildx build --platform linux/arm/v7 --tag <username>/<image name>:<tag> .
Adding a --push
flag will automatically push the image to your registry when it's built.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | kenneth |
Solution 2 | Michael Lamb |