How to Dockerize a Spring Boot 3 application

preview_player
Показать описание
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

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.
Рекомендации по теме
Комментарии
Автор

You are awesome sir. Thank you so much for this.

manisa
Автор

0:58 the walmart phun was painful 😢

Well executed dad joke. Salute, Sir.! 👌✌

Voldeblort
Автор

Can you please explain when to use apache image and deploy the war file and when to do it the way you explained? For kube clusters, production maybe?

Niophyte
Автор

Hi Mackenzie. How can I connect to my local MySQL from the Docker container. My database is installed in my host Ubuntu 22.04

kimelironald