-1

Consider this example from the docs:

# syntax=docker/dockerfile:1
FROM node
WORKDIR /app
COPY package.json yarn.lock .    # Copy package management files
RUN npm install                  # Install dependencies
COPY . .                         # Copy over project files
RUN npm build                    # Run build

By installing dependencies in earlier layers of the Dockerfile, there is no need to rebuild those layers when a project file has changed.

Which layers can be skipped here?

By my understanding, npm command is black-box for docker, so docker doesn't know what npm's inputs are and what will it produce. If so, then docker has to always run npm install and npm build commands, which means caching is useless here.

What am I missing here?

IndustryUser1942
  • 1,052
  • 1
  • 8
  • 12
  • Does this answer your question? [Is docker caching useless when RUN is involved?](https://stackoverflow.com/questions/76873881/is-docker-caching-useless-when-run-is-involved) – jonrsharpe Aug 24 '23 at 12:04
  • In same way as https://docs.docker.com/ answer it. (theoretically answer is there, but the exact point is not too clear) – IndustryUser1942 Aug 25 '23 at 07:05

1 Answers1

-1

Docker just assumes that all commands are pure and have no side effects and caches just by commands string representation.

(as mentioned here https://stackoverflow.com/a/76873905/10544569, running side-effectful script is useless in docker)

IndustryUser1942
  • 1,052
  • 1
  • 8
  • 12