How does layer caching work during a build?

Each instruction creates a layer. If an instruction and its inputs are unchanged, the cached layer is reused; once one layer changes, every later layer rebuilds. Copy dependency files and install them before copying the rest of the source.