1

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?

RobC
  • 22,977
  • 20
  • 73
  • 80
akshat
  • 107
  • 8
  • 1
    The container image should be as small as possible and so I would suggest not. – Raman Sailopal Mar 31 '21 at 12:45
  • When copying cache dir: size: 182 MB, Build time: 37s When not copying cache dir: size: 191 MB, Build time: 200+s This is a little unexpected :( @RamanSailopal – akshat Apr 02 '21 at 05:14

0 Answers0