Skip to content

Updates to node_modules on image rebuild not reflected in container's node_modules volume #2032

@mekarpeles

Description

@mekarpeles

Description

Because we volume mount ./ to /openlibrary, /openlibrary/node_modules (which is populated when npm install is run inside the Dockerfile) gets rewritten by what's in the local directory. We've solved this issue by adding another volume mount specifically to /openlibrary/node_modules. This has had the unintended consequence that if the images are rebuilt, even though npm install is run there, when they are launched, they attach to the volume which contains the old version of /openlibrary/node_modules. So npm install has to be run again to update the volume.

What we want:

  1. Rebuilding the image should run npm install
  2. Running docker-compose up should NOT require running npm install
  3. Running docker-compose up should have the same npm versions from the image.

External links:

  • https://jdlm.info/articles/2016/03/06/lessons-building-node-app-docker.html#the-node_modules-volume-trick : a guide on how this problem was handled in 2016 on another project. They use the same kind of volume mount trick, but using non-named / non-persistent volumes. I will investigate whether moving back to non-named volumes will guarantee they are created fresh every docker-compose up with the correct and latest node_modules from the base image.
    The article has a very good description of the node_modules problem in the section "The node_modules Volume Trick" and how mounting the local dev dir overwrites the installed image modules with the empty host node_modules. The blue / red filenames is a great way to illustrate a problem (I have found) difficult to describe clearly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Affects: ConfigurationRelated to the configuration of the dev/staging/prod environments, CI, docker, etc. [managed]Lead: @cdriniIssues overseen by Drini (Staff: Team Lead & Solr, Library Explorer, i18n) [managed]Module: DockerIssues related to the configuration or use of Docker. [managed]Priority: 3Issues that we can consider at our leisure. [managed]Theme: DevelopmentIssues related to the developer experience and the dev environment. [managed]Type: Refactor/Clean-upIssues related to reorganization/clean-up of data or code (e.g. for maintainability). [managed]

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions