Docker multi-stage builds addresses the issue. See also How to analyze Docker images layers and content with Dive.