Skip to content

Conversation

@ottnorml
Copy link
Contributor

@ottnorml ottnorml commented Apr 8, 2023

This PR contains a number of optimizations to reduce the size of the published Docker image.

@ottnorml ottnorml requested a review from alexjustesen as a code owner April 8, 2023 21:05
@ottnorml ottnorml changed the title Docker optimizations Reduce the size of the published Docker image Apr 8, 2023
@alexjustesen
Copy link
Owner

@ottnorml out of curiosity why remove the separate RUN commands? I was always under the impression that separate commands let Docker cache those and not necessarily have to download it again.

@ottnorml
Copy link
Contributor Author

ottnorml commented Apr 9, 2023

Best practices for creating Docker images state that images should be as small as possible and should not contain files that are unnecessary for the actual final purpose of the image.

For me, caches of package managers such as APT and Composer fall into this category files, since on the one hand they are not needed for the operation of the image and on the other hand they can become obsolete and thus can cause unforeseen problems later. In addition, they also increase the size of the image.

For me these disadvantages far outweigh the advantage of a shorter build time.

I combined the RUN statements to still be able to use the cache as much as possible while preventing it from being present in the final image. This also had the practical side effect of reducing the number of layers, which further reduces the size of the image.

@alexjustesen alexjustesen merged commit 7d3e0e9 into alexjustesen:main Apr 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants