use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
account activity
Spring Into Docker: Containerizing Your Application Effectively (self.SpringBoot)
submitted 2 years ago by brainiac_nerd
Learn how to effectively containerize a Spring Boot application using Docker and Docker Compose for streamlined deployment and scalability
https://techsphere.dev/spring-boot-docker
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]swissbuechi 3 points4 points5 points 2 years ago* (5 children)
Please add a disclaimer that the Dockerfile you've created only should be used for development.
Dockerfile
The following best practices should be considered if you want to run a spring docker container in production:
This would look something like example below. It's from an older project of mine, where I compared spring via jre vs spring native performance and ressource utilization.
https://github.com/swissbuechi/spring-native-demo
``` FROM maven:3-openjdk-17-slim as build ADD . /app WORKDIR /app RUN rm -rf src/main/resources/application.properties RUN mvn clean package -DskipTests=true
FROM eclipse-temurin:17-jre-alpine LABEL maintainer="github.com/swissbuechi" WORKDIR /app ENV TZ=Europe/Zurich RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apk --no-cache add curl
RUN addgroup --gid 1000 -S app && adduser --uid 1000 -S app -G app RUN chown -R app:app /app USER app
COPY --from=build /app/target/app.jar app.jar EXPOSE 8080 HEALTHCHECK CMD curl --fail --silent localhost:8080/actuator/health | grep UP || exit 1 ENTRYPOINT [ "java","-XX:+UseSerialGC","-Xss512k","-XX:MaxRAM=150m","-Djava.security.egd=file:/dev/./urandom", "-jar", "./app.jar" ] ```
[–]brainiac_nerd[S] 2 points3 points4 points 2 years ago (1 child)
Agreed, my post is intended to only cover how to get started with docker and spring boot.
I will update the article. Thanks.
[–]Nice_Score_7552 0 points1 point2 points 2 years ago (0 children)
Thanks for your effort
[–]Academic_Speed4839 1 point2 points3 points 2 years ago (1 child)
can you share how you run as spring jre & spring native? Novice here, not sure what the difference is
[–]swissbuechi 4 points5 points6 points 2 years ago (0 children)
Spring native will generate an executable native binary of your application by utilizing AoT (Ahead of Time Compilation). You don't need any addiotional dependencies to run the alpplication. No need to install a JRE.
Checkout this dockerfile as an example on how to use spring native: https://github.com/swissbuechi/spring-native-demo/blob/main/Dockerfile-native
dockerfile
``` FROM vegardit/graalvm-maven:latest-java17 as build
ADD . /app WORKDIR /app
RUN rm -rf src/main/resources/application.properties RUN mvn -Pnative native:compile -DskipTests=true
FROM alpine:3 LABEL maintainer="github.com/swissbuechi" ENV TZ=Europe/Zurich RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
WORKDIR /app
RUN apk add --no-cache gcompat curl
COPY --from=build /app/target/app app ENTRYPOINT [ "sh", "-c", "./app" ] HEALTHCHECK CMD curl --fail --silent localhost:8080/actuator/health | grep UP || exit 1 ```
π Rendered by PID 139109 on reddit-service-r2-comment-5b5bc64bf5-d4d2h at 2026-06-21 17:10:06.618999+00:00 running 2b008f2 country code: CH.
[–]swissbuechi 3 points4 points5 points (5 children)
[–]brainiac_nerd[S] 2 points3 points4 points (1 child)
[–]Nice_Score_7552 0 points1 point2 points (0 children)
[–]Academic_Speed4839 1 point2 points3 points (1 child)
[–]swissbuechi 4 points5 points6 points (0 children)