docker does not save a packagejson file when running npm installation

This is happening because first you are building an image out of your Dockerfile, which contains this commands:

WORKDIR /var/www
RUN npm install

But right now this directory is empty. It’s only after the container is created, bind mounting will take place. You can read more about it in the docs, it states:

A service definition contains configuration that is applied to each container started for that service, much like passing command-line parameters to docker run. Likewise, network and volume definitions are analogous to docker network create and docker volume create.

If you need to have this file available at the image build time, I’d suggest using COPY command, like:

COPY ./client/package*.json ./
RUN npm install

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top