How many layers are needed?

I am writing this as we transition from the warm last days of summer, into still warm days of autumn into possibly colder days of winter. The question that always arises, same in spring, is how many layers do I need to wear? I did not know the same question applies to Docker.

Single layer, best layer

So many would argue, as I would have until now, that a single layer is the best layer and it will be better than anything else. In terms of how big the image is, it will help to make it smaller. However in terms of development flow you need to rebuild the entire image all the time every time. This means that development for a singular fix of the entrypoint.sh script for example takes long. Every environment variable that will be changed will force the entire build process.

I would say the size will impact every download the image in the future of every client and will cost more time there, but it will take a lot of clients to make it equivalent of loss that you will incur during the development process of having a singular layer.

Multiple layers, best layers

There are others that argue many many many layers is the way to go because everything is separated and easier to manage caching and development flow. I think this is true, however I think there needs to be a little nuance and actually best of both worlds needs to be used to attain maximum gain.

Multi layer for dev, single layer for distribution

I think the best is to have a Dockerfile with dependencies on one layer, entrypoint on another layer, environment variables maybe at the end and just make it so that whatever changes the most is at the bottom so the development time is cut as much as possible. Then consolidate all layers into one layer and move that to distribution so the image will be as small as possible.