Post

Docker Multi-Stage Builds: Smaller, Cleaner Images

Docker 17.05 introduced multi-stage builds.

Benefits:

  • No build tools in final image
  • Clear separation of stages
  • Smaller image sizes

Example:

1
2
3
4
5
6
7
8
9
FROM maven:3.5-jdk-8 as builder
WORKDIR /app
COPY . .
RUN mvn clean package

FROM openjdk:8-jre
COPY --from=builder /app/target/app.jar /app.jar
CMD ["java", "-jar", "/app.jar"]

This post is licensed under CC BY 4.0 by the author.