How to cache node_modules on Docker build? How to cache node_modules on Docker build? docker docker

How to cache node_modules on Docker build?


I'm not sure whether it is the root of the error, but try to specify the destination folder in the ADD command and not the destination file.

ADD package.json /src

Moreover, you can use COPY instead of ADD (ADD can work with url and archives but you don't need it here).

You can also specify your working directory earlier in the file.

Try with this code :

    # This image will be based on the official nodejs docker image    FROM node:4.2.1        RUN npm install -g jspm@0.17.0-beta.7 && \        npm install -g gulp && \        npm install -g tsd    # Set in what directory commands will run    WORKDIR /src        # Use changes to package.json to force Docker not to use the cache    # when we change our application’s nodejs dependencies:    COPY package.json ./    RUN npm install        # Put all our code inside that directory that lives in the container    COPY . ./        # Install dependencies    RUN tsd reinstall -so && \        jspm install && \        gulp build -p        # Tell Docker we are going to use this port    EXPOSE 3000        # The command to run our app when the container is run    CMD ["npm", "run", "start-production"]