I've recently started to learn Docker and have been trying to learn how to use multi-stage build. The documentation here: https://docs.docker.com/develop/develop-images/multistage-build/ Says
The end result is the same tiny production image as before, with a significant reduction in complexity. You don’t need to create any intermediate images and you don’t need to extract any artifacts to your local system at all.
There's also an example I don't think is necessary to copy here, however I've also started a small Spring Boot project with Gradle that I want to containerize. Here's my Dockerfile:
# using multi-stage to avoid manual ./gradlew build
FROM openjdk:11 as build
COPY gradle gradle
COPY build.gradle build.gradle
COPY gradlew gradlew
COPY gradlew.bat gradlew.bat
COPY settings.gradle settings.gradle
COPY src src
RUN ./gradlew build
# final image
FROM openjdk:11
WORKDIR /service
COPY --from=build /build/libs/*.jar /service/app.jar
ENTRYPOINT ["java","-jar","/service/app.jar"]
This is docker images
command output before the build:
REPOSITORY TAG IMAGE ID CREATED SIZE
openjdk 11 5c6e71a989bc 12 days ago 627MB
Build command: docker build . -t sdemo:1.2.1
And the docker images
after it's finished:
REPOSITORY TAG IMAGE ID CREATED SIZE
sdemo 1.2.1 24ea50770b2a 13 seconds ago 672MB
<none> <none> a1f8e74e1d81 20 seconds ago 960MB
openjdk 11 5c6e71a989bc 12 days ago 627MB
As you can clearly see, I've got 2 images more instead of one, and the unnamed one is of ridiculous size of 960MB. What is causing this problem? Also, if it's relevant, I'm on a virtual box machine running Ubuntu.
The whole project is located under https://github.com/vincent2704/demoSpringBootApp, version 1.2.1 at the moment of posting this question.