How do I reduce Spring Boot's docker image size?

With my current Dockerfile configuration for a barebones spring app (straight from start.spring.io) with dependencies like web, redis, postgres, security, mail sender, etc, the size of the image is at ~350mb and I was told this was pretty large for a barebones application. Here's my dockerfile
# Build stage
FROM amazoncorretto:17-alpine AS build
WORKDIR /app

RUN apk add --no-cache maven

COPY pom.xml .
RUN mvn dependency:go-offline -B

COPY src ./src
RUN mvn package -DskipTests -B

# Runtime stage
FROM amazoncorretto:17-alpine
WORKDIR /app

COPY --from=build /app/target/tunnityserver-*.jar ./tunnityserver.jar

EXPOSE 8080

ENTRYPOINT ["java", "-jar", "tunnityserver.jar"]
# Build stage
FROM amazoncorretto:17-alpine AS build
WORKDIR /app

RUN apk add --no-cache maven

COPY pom.xml .
RUN mvn dependency:go-offline -B

COPY src ./src
RUN mvn package -DskipTests -B

# Runtime stage
FROM amazoncorretto:17-alpine
WORKDIR /app

COPY --from=build /app/target/tunnityserver-*.jar ./tunnityserver.jar

EXPOSE 8080

ENTRYPOINT ["java", "-jar", "tunnityserver.jar"]
how can I optimise it?
6 Replies
JavaBot
JavaBotβ€’2mo ago
βŒ› This post has been reserved for your question.
Hey @Milk Packet! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
lisan
lisanβ€’2mo ago
Medium
How to reduce the size of a Docker image using dive
Reducing the overall image size is key to building and launching Docker images as quickly as possible. The smaller the image size, the less…
lisan
lisanβ€’2mo ago
Medium
Reduce the size of the Docker Image
To effectively reduce the size of your Docker images, you can implement several best practices and optimization techniques
JavaBot
JavaBotβ€’2mo ago
πŸ’€ Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
longtime-coder
longtime-coderβ€’2mo ago
maybe you are trying to do a bit too much in one container? Usually we want applications to be small. We then create several as needed, each fulfilling a separate purpose.
JavaBot
JavaBotβ€’2mo ago
πŸ’€ Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Want results from more Discord servers?
Add your server