I work in a small team with a private Docker registry. We won’t ever meet the 42 layers restriction and care mostly about performance and development speed.
If so, should I minimize the number of docker layers?
In your case, no.
What needs to be minimized is the build time, which means:
- making sure the most general steps, and the longest are first, that will then cached, allowing you to fiddle with the last lines of your Dockerfile (the most specific commands) while having a quick rebuild time.
- making sure the longest RUN command come first and in their own layer (again to be cached), instead of being chained with other RUN commands: if one of those fail, the long command will have to be re-executed. If that long command is isolated in its own (Dockerfile line)/layer, it will be cached.
That being said, the documentation you mention comes from docker/docker.github.io
, precisely PR 4992 and PR 4854, after a docker build LABEL
section.
So this section comes after a similar remark about LABEL
, and just emphasize the commands creating layers.
Again, in your case, that would not be important.