Our Node.js project requires Node version 14 or higher, so I set that in the package.json
"engines": {
"node": ">=14"
}
But the Dockerfile (some other developer wrote it) did not respect that, it looks like these
FROM node:12-alpine3.14
COPY package*.json ./
ENV NODE_ENV production
# RUN npm install -g npm@latest
RUN npm install
...
docker build
succeeded but docker run
failed exactly because of node 12.
How can I make docker build
respect the nodejs version I set in the package.json?
Please note that the problem is easily fixed by just update FROM node:14-alpine3.14
. But that is not my question is about. For example, say in the future the project needs node16 and we update that in package.json
but forget to update the Dockerfile, I need a way to make docker build failed for that reason.