Docker had a great cache mechanism, and you can easily use it to improve your image build time.
You can use the below Dockerfile to run a simple nodejs application, but for every image build the command
npm install will be executed.
FROM nodeADD . /codeWORKDIR /codeRUN npm installCMD npm start
A great optimization to the previous Dockerfile is to run
npm install before adding your codebase. For this you will have to add
package.json and to run
nmp install, before you add your codebase.
FROM nodeADD ./package.json /code/package.jsonWORKDIR /codeRUN npm installADD . /codeCMD npm start
npm install are cached and will be rerunned only if your
package.json changes, making your image build time faster.