I have a Dockerfile that looks like this:
COPY ./aaa/package.json ./aaa/package.json
COPY ./bbb/package.json ./bbb/package.json
COPY ./ccc/package.json ./ccc/package.json
WORKDIR aaa
RUN npm install
COPY ./aaa ./aaa
Basically module aaa uses bbb and ccc as local npm modules
Is it possible to write it so that the first 3 COPY instructions are done with a single COPY instruction so that they are 1 layer instead of 3? (I realize there's a 4th layer with the last COPY)
I still need the last COPY separate. That's intentional. The reason for splitting out the last layer is that the npm install is only dependent on the package.json files, and this way if I change source code, it doesn't need to rebuild all layers, just the last one. Only if I change the package.json files does it need to rebuild the first layer and do a new npm install. This was a fine pattern for me using a single module, but now that I've got a main module that is using local submodules (local npm modules) I'm stuck on how to reduce the number of COPY instructions to reduce the number of layers. A full description of this technique is documented (and recommended) at nodejs.org in the article "Dockerizing a Node.js web app"
Worth mentioning that it technically works as is, but it's inefficient because it creates extra layers for the extra copies when it seems like it should be possible to somehow get the first three COPY instructions combined to get one layer.