I read a docker blog post that advises to re-run npm install when building a docker container because node_modules may contain binaries compiled for your host OS, and if it’s different then the container OS, you’ll get errors trying to run your app when you’re bind-mounting it from the host for development.
Yarn documentation states we should keep yarn.lock
, yarn/cache
, yarn/plugins
and yarn/release
folder checked-into the repo. This is how my Dockerfile looks:
FROM node:14.16.0-slim
ENV NODE_ENV=production
COPY . /app
WORKDIR /app
RUN yarn set version 2.4.1
RUN yarn install
USER node
EXPOSE 8080
CMD ["yarn", "run", "start"]
Following above blog's advice, should one ignore .yarn
folder or not?