'RUN yarn doesn't create node_modules inside docker image

I have a dockerfile that should build an image of a node. In the build phase, it builds right, however, in the production phase, the node_modules folder does not appear inside the image.

I'm not mapping any volumes, just trying to build the image. Could anyone help me with this? I don't understand why this is happening.

FROM node:16.14-alpine3.15 as builder

ENV NODE_ENV=development

WORKDIR /home/node/app
COPY package*.json .
COPY tsconfig.json .
RUN yarn install
COPY . .
RUN yarn build

FROM node:16.14-alpine3.15 as production

ENV NODE_ENV=production

RUN mkdir -p /usr/src/app
VOLUME /usr/src/app
WORKDIR /usr/src/app

RUN mkdir logs

COPY package*.json .
COPY yarn.lock .
RUN yarn install --production

RUN ls -la
RUN ls -la node_modules

COPY --from=builder /home/node/app/dist /usr/src/app/dist

EXPOSE 3333
CMD ["yarn", "start"]

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source