I'm a Systems Reliability and DevOps engineer for Netdata Inc. When not working, I enjoy studying linguistics and history, playing video games, and cooking all kinds of international cuisine.
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.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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 ownRUN
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:
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.