Skip to content

Improve Layer Count#1996

Closed
georglauterbach wants to merge 2 commits intomasterfrom
improve-layer-count
Closed

Improve Layer Count#1996
georglauterbach wants to merge 2 commits intomasterfrom
improve-layer-count

Conversation

@georglauterbach
Copy link
Copy Markdown
Member

Description

Lowers the layer count (by 18 layers) just by using \. Does not change anything else. Plain and simple.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Improvement (non-breaking change that does improve existing functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (README.md or the documentation under docs/)
  • If necessary I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@georglauterbach georglauterbach added area/ci area/dependency priority/medium kind/improvement Improve an existing feature, configuration file or the documentation labels May 22, 2021
@georglauterbach georglauterbach requested a review from a team May 22, 2021 19:14
@georglauterbach georglauterbach self-assigned this May 22, 2021
@georglauterbach georglauterbach changed the title improve Layer Count Improve Layer Count May 22, 2021
Copy link
Copy Markdown
Member

@wernerfred wernerfred left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wow, didn't know that is possible tbh 🤣

Did a quick research and found this page: https://docs.docker.com/develop/develop-images/dockerfile_best-practices/

In older versions of Docker, it was important that you minimized the number of layers in your images to ensure they were performant. The following features were added to reduce this limitation:

Only the instructions RUN, COPY, ADD create layers. Other instructions create temporary intermediate images, and do not increase the size of the build

So do we really have a benefit or is this just a local number of layers that is decreased without any impact to the final image anyways?

Comment thread Dockerfile
@georglauterbach
Copy link
Copy Markdown
Member Author

georglauterbach commented May 22, 2021

Oh wow, didn't know that is possible tbh rofl

Did a quick research and found this page: https://docs.docker.com/develop/develop-images/dockerfile_best-practices/

In older versions of Docker, it was important that you minimized the number of layers in your images to ensure they were performant. The following features were added to reduce this limitation:
Only the instructions RUN, COPY, ADD create layers. Other instructions create temporary intermediate images, and do not increase the size of the build

So do we really have a benefit or is this just a local number of layers that is decreased without any impact to the final image anyways?

I was wondering this as well when I just stumbled upon this with a fellow student. After what you've posted, this does not actually add a performance benefit, but looking at https://hub.docker.com/layers/mailserver/docker-mailserver/edge/images/sha256-1caa65c0f7f85428a145922181093304b20baac57ca8afbdf4d0fa1115e031aa?context=explore for example, they do appear as a layer?

We don't need to merge this at all, I just looked at the link above and thought: "Hey, maybe we can reduce layers here :)"

@wernerfred
Copy link
Copy Markdown
Member

Then this might be more a "style" question. Imho i see no problem with all ENV and LABEL to appear as a single layer on dockerhub although there is no change in fact.

Is this possible for ARG as well?

@wernerfred wernerfred added this to the v10.0.0 milestone May 22, 2021
@georglauterbach
Copy link
Copy Markdown
Member Author

Then this might be more a "style" question. Imho i see no problem with all ENV and LABEL to appear as a single layer on dockerhub although there is no change in fact.

Is this possible for ARG as well?

You can apparently not do this for ARG. I had no problem with the style as is, but my fellow said he knows using \ to concatenate the LABEL and ENV command to be good style.

Copy link
Copy Markdown
Member

@wernerfred wernerfred left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍🏻
From my perspective go ahead 🚀

@georglauterbach
Copy link
Copy Markdown
Member Author

georglauterbach commented May 22, 2021

I will merge #1989 first when CI passes, then I will merge this PR and then announce the feature freeze in the maintainers discussion 🎉

@wernerfred wernerfred mentioned this pull request May 22, 2021
9 tasks
@casperklein
Copy link
Copy Markdown
Member

I think, this is just a docker hub thing. LABEL, ENV etc. do not add additional layers. They just end up in the manifest.

You can verify this for example with dive. Or take a look at how many layers are pulled with docker pull. There will be no difference after this merge.

I don't open the style discussion 😄 That is just personal preference, if you prefer \ syntax. What I do for example from time to time is grep ENV Dockerfile to get all ENVs. That would not be possible anymore (in that easy form). No show-stopper. My preference would be to leave it as it is.

@georglauterbach
Copy link
Copy Markdown
Member Author

georglauterbach commented May 22, 2021

I think, this is just a docker hub thing. LABEL, ENV etc. do not add additional layers. They just end up in the manifest.

You can verify this for example with dive. Or take a look at how many layers are pulled with docker pull. There will be no difference after this merge.

I don't open the style discussion smile That is just personal preference, if you prefer \ syntax. What I do for example from time to time is grep ENV Dockerfile to get all ENVs. That would not be possible anymore (in that easy form). No show-stopper. My preference would be to leave it as it is.

I understand. As this was started as a real improvement when it comes to layer count, but now only is a style thing. I will close this:) I actually prefer the way it is ATM over this PR, but I figured in the beginning if there was a real benefit, it would be worth it.

Feature freeze is now active :D

@georglauterbach georglauterbach deleted the improve-layer-count branch May 22, 2021 20:56
@casperklein
Copy link
Copy Markdown
Member

What I do, to ultimately "optimize" the layer count to 1:

FROM docker.io/debian:buster-slim as build
[..]
# build final image
FROM scratch
COPY --from=build / /

The only disadvantage of this approach is, that you lose the ability to use a base-image (debian). Now you have one image (1 layer) without dependency to an upstream image (debian).

@wernerfred wernerfred removed this from the v10.0.0 milestone May 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/ci kind/improvement Improve an existing feature, configuration file or the documentation priority/high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants