Where to place CMD / EXPOSE / etc

hi all. I’m trying to write my own ‘best practices’ Dockerfile. My question is: does it make any sense to put EXPOSE / CMD at the top of Dockerfile? As far as I understand it can potentially save some bits since CMD / EXPOSE are normally the same between software versions. I suspect I’m missing something since all ‘official’ images I inspected have CMD / EXPOSE at the bottom of a Dockerfile.

It shouldn’t matter too much, placing at the bottom is mostly convention. If you change it and it’s at the top it will bust cache for docker build.

I’m not sure what this is about. But at any rate, assuming that the content addressable digest for the CMD or ENTRYPOINT layers is the same between image builds, you’ll save at least some bandwidth on push / pull no matter where you place the instruction in the Dockerfile, since the registry mechanics only send layers that haven’t been seen before on the registry (push) or pull-ing computer.