A dockerfile is processed from top to the bottom, each instruction compared against cached layer. When an instruction is found without a cached layer, this instruction create a new container image layer.
Include the most frequently changing steps at the end of your dockerfile. Example: -