Skip to content

Latest commit

 

History

History
14 lines (7 loc) · 824 Bytes

docker.md

File metadata and controls

14 lines (7 loc) · 824 Bytes

Dockerfile Caching and Optimization

In Docker, each command in a Dockerfile creates a new layer in the image, and Docker caches these layers. When rebuilding an image, Docker reuses the cached layers if the commands and their contexts (files and other inputs) haven't changed. This caching mechanism speeds up the build process significantly.

Improving Caching:

To better leverage Docker's caching, especially focusing on package-lock.json:

Minimize the number of layers by combining commands where possible.

Install dependencies (npm ci) immediately after copying package.json and package-lock.json to ensure that changes to these files invalidate the cache as early as possible.

Avoid running apt-get update without an immediate apt-get install in the same RUN command to prevent using outdated package lists.