Use Docker's multi-stage builds to reduce image size #3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Docker images is built up from a series of layers. Each layer represents an instruction in the image’s Dockerfile. Meaning every instructions in the image's Dockerfile will have it's own layer, and will still exists on the final image.
I see that in line 20 on original Dockerfile, you are removing some dirty stuffs from gradle for runtime, that's good, but what you don't know that there is still a leftover in
/root/.gradle
, you could also remove it manually usingrm
but using multi-stage like this is more proper/better or you can say cleanWith multi-stage builds, every dirty stuffs while compiling will not go into the final image, so no need to delete
/root/.gradle
or even/tmp/*
, so with that, this PR will reduce image size from 514MB to 232MBOld image layers:
New image layers:
And, on the final layer of new image: