These orderings are made for optimizing build time using Docker's built-in caching mechanism.
Rule of thumbs:
Parts that change often (e.g. codebase) should be placed near bottom of Dockerfile, and vice-versa. Parts that rarely change (e.g. dependencies) should be placed at top.