If you're doing cloud native development with Spring Boot, you'll need to Dockerize your executable JAR file at some point in time.
There are a variety of Maven, Gradle and even Jenkins plugins or add-ons that will do that. But why not just do it on your own? It's easy.
Just create a Dockerfile in the same folder as your Spring Boot executable JAR file. The contents of the JAR file look something like this:
FROM eclipse-temurin:17-jdk-alpine
COPY spring-app-1.0.jar spring-app-1.0.jar
ENTRYPOINT ["java", "-jar", "spring-app-1.0.jar"]
Then, just build the JAR. In the same folder as the JAR files and the Dockerfile, run:
docker build -t spring-app:latest
That will build your image and then you can run it locally with a command like:
docker run -p 8099:8080 -t spring-app:latest
If you really wanted to, you could tag the image:
docker images (to find your image id)
docker tag **??a70e7b4f9e4d?? cameronmcnz/spring-app:latest
Then just do a Docker login and push the image to Docker hub!
docker long
docker push cameronmcnz/spring-app:latest
It really couldn't be easier to Dockerize a Spring Boot 3 app and push that Spring Boot docker image up to DockerHub.
Негізгі бет How to Containerize Spring Boot applications
Пікірлер: 11