Docker images should be kept as small and efficient as possible. If there are files on the shipping image that you won’t be using, you should get rid of them throughout the build process.
When you breakdown your commands into multiple RUNs, docker adds a corresponding layer to that image. The results are the alterations to the file system that may be inspected with docker diff on the intermediate container.
Removing unnecessary files in a separate RUN defeats the purpose of reducing the image footprint because, on top of a new layer is created, Docker will still keep the deleted files in the previous inactive layer, which is shipped over the network and stored on disk.
|
|
By combining commands in a single RUN, you avoid the creation of a new layer and the retention of unnecessary files.