Le immagini Docker vengono costruite in livelli — ogni istruzione del Dockerfile crea un livello, e Docker memorizza nella cache i livelli per accelerare le ricostruzioni. Comprendere i livelli e la cache è fondamentale per scrivere Dockerfile efficienti che si compilano velocemente e producono immagini più piccole.
Livelli — ogni istruzione aggiunge un livello
Each Dockerfile instruction (FROM, RUN, COPY, etc.) creates a read-only LAYER:
→ layers stack to form the image; layers are CACHED and SHARED between images
→ if a layer is unchanged, Docker REUSES the cached layer (skips rebuilding it)
→ Layer caching makes rebuilds fast — only changed layers (and those AFTER) rebuild.
