Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does cleaning the user yarn cache will affect docker image?

While building the docker images, after the below steps

  • Installing dependencies (RUN yarn install)
  • generate build (RUN ng build --prod)

If I clean the yarn cache from usr location using below command in docker file, will it affect afterward when I run the docker image?

RUN rm -rf /usr/local/share/.cache/yarn/*

as the docker images size was huge 1.2 GB so I have clean the above location that has close to 450+ MB.

I am using a lower version of docker (for a specific reason) which doesn't support multistage build.

Also, is the above command is equivalent to RUN yarn clean cache?

FROM node:10-alpine

WORKDIR /app

COPY . /app

RUN apk --no-cache add yarn \
    && yarn install \
    && ng build --prod \
    && rm -rf /var/cache/apk/* \
    && rm -rf /usr/local/share/.cache/yarn/*

EXPOSE 3000

CMD ["npm", "run", "start"]
like image 763
Dan Avatar asked May 27 '20 09:05

Dan


1 Answers

yarn Version 1

You can safely remove cache files, it will not affect your application. There's even a dedicated command for that:

$ yarn cache clean

yarn Version 2

With Plug'n'Play, however, clearing the cache will very likely break your application because dependencies are no longer placed in node_modules. Here's what the documentation says:

In this install mode (now the default starting from Yarn v2), Yarn generates a single .pnp.js file instead of the usual node_modules. Instead of containing the source code of the installed packages, the .pnp.js file contains a map linking a package name and version to a location on the disk, and another map linking a package name and version to its set of dependencies. Thanks to this efficient system, Yarn can tell Node exactly where to look for files being required - regardless of who asks for them!

The location on the disk is cache.

You can get the old behavior back by placing this in your .yarnrc.yml file.

nodeLinker: node-modules

Read more about Plug'n'Play here

like image 138
Daniel Avatar answered Sep 28 '22 12:09

Daniel