Rearrange dockerfile to use cache