Break down how much each Dockerfile instruction adds to your final image layers.
Each Dockerfile instruction (RUN, COPY, ADD) creates a new read-only layer in the union filesystem. The total image size equals the base image plus all added layers. Identifying which layers contribute the most size helps optimize the Dockerfile by combining commands, using multi-stage builds, or choosing smaller base images.
Total Image Size
totalSize = baseImage + (numLayers × avgLayerSize)
Chain multiple RUN commands with && to produce a single layer, and clean up temporary files within the same RUN instruction so deleted content never appears in a layer.
No — total size is the sum of all layers regardless of order. However, ordering affects cache invalidation: placing frequently-changing instructions last maximizes cache hits for earlier layers.