Why do node_modules keep disappearing from docker after build?

I’m mimicking the setup found here https://github.com/mjhea0/node-docker-workflow. Using docker-compose to link 2 docker containers (node, redis).

Here’s the circle ci file:

  • Packer,Dockramp vs Dockerfile
  • How to know if my program is completely started inside my docker with compose
  • Docker- what real value does it bring for our team?
  • Jenkins - Docker integration
  • Jenkins docker plugin and linked slaves
  • Java Maven Project Docker Integration Tests
  • machine:
        - docker
        - sudo pip install -U docker-compose
        - docker-compose run -d --no-deps node
        - cd node; npm test

    And here is my node Dockerfile:

    FROM dockerfile/nodejs
    RUN mkdir /src
    RUN npm install nodemon -g
    WORKDIR /src
    ADD . /src
    RUN npm install
    EXPOSE 3000
    CMD npm start

    The tests are constantly failing because chai can’t be found. This is due to node_modules disappearing once the build is complete.

    Literally between these 2 steps in the circle.yml file node_modules are installed by npm install, and then they’re gone by the time the npm test command is run.

        - docker-compose run -d --no-deps node
        - cd node; npm test

    I can’t figure out why this is happening. As i’m just starting out with Docker, can someone please (in laymens terms) explain fairly thoroughly what is wrong with the repo i’m using above, and how to solve it.


  • Pycharm not showing all files from django external library
  • Docker-compose migrating from links to networking MongoDB database issue
  • Docker : Drupal container linked to mysql container can't connect to mysql during Drupal installation
  • Strange Docker + Celery Bug
  • Hostname for website running inside Docker
  • How to install a python package with all the dependencies into a Docker image?
  • One Solution collect form web for “Why do node_modules keep disappearing from docker after build?”

    Well, it turns out it was something very, very simple, and probably rather silly/obvious.

    The tests aren’t being run inside the container.

    docker-compose run -d --no-deps node

    This line runs the container in detached mode. Which means when the next command runs, it’s running outside the container.

    To solve this, simply remove the -d, so the next command runs inside the container.

    docker-compose run --no-deps node


    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.