Skip to content
markdown guide

The biggest issue (no pun intended) with having more layers is image size. Because of how Docker images work, each layer that changes file contents or adds files adds the total size of all files it adds or modifies to the final image size, even if later layers remove those changes or files.

This doesn't sound very significant, but it can have a huge impact. This is a large part of why adding packages to a base image is almost always done as a single RUN line that updates package caches, installs the required packages, and then nukes the caches, as doing each part as it's own RUN line can inflate the resultant image size by hundreds of megabytes.

There are a couple of other far less significant downsides to having lots of layers:

  • There's a small bit of overhead in terms of image size per layer even ignoring the point made above. It's usually not enough to matter, but it is there.
  • Pulls take a bit longer for each layer in the image, even if the total image size is the same, because each layer can only be extracted one at a time.
  • There's also a small amount of per-layer overhead on filesystem lookups inside running containers (stuff like listing directories or checking permissions on a path). This is also usually not enough to matter, but is still there.

On the other side of the coin, adding more layers can help you improve build times by allowing you to leverage caching better. However, this can lead to all kinds of issues if you're not careful about dropping the cache when you need to.


I'd say you want the right layers. So as it said, a php installed layer then application. The multiparty docker can be good to limit final image size, but don't use it as a poor man's build system.

Classic DEV Post from Jul 2 '19

How to refill someone’s “cup?”

Sometimes we rely so much on our friends and coworkers that we often forget to ma...

Dimitrios Desyllas profile image
Greedings I am Dimitrios Desyllas aka pc_magas. I am a php software engineer in e-table. I am interested in electron, C++, privacy enhancing terchnologies and cryptography