Skip to content

.tip

· one of the small things

Copy the lockfile before the source in a Dockerfile

Every layer after a changed file gets rebuilt. If COPY . . comes before pnpm install, a one line code change reinstalls everything.

COPY package.json pnpm-lock.yaml ./
RUN pnpm install --frozen-lockfile
COPY . .

Now the install layer stays cached until a dependency changes, which happens a few times a month and not a few times an hour.

dockerci