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:

  • Docker continuous deployment workflow
  • How should I combine docker containers?
  • How to do a custom deploy using ssh with Travis CI?
  • Packer,Dockramp vs Dockerfile
  • what's the best way to use command line applications in a docker environment?
  • Jenkins - Cannot run program “docker”
  • 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.


  • Sharing a single file from host machine with Docker Container and having the Container r+w to same file
  • Running composer on Elastic Beanstalk with multi docker environment
  • Can't get Docker image after windows installation
  • redirect the output of docker-exec
  • Concourse pending for long time before running task
  • Backup + Version Docker Containers by adding Volumes and Commit
  • 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.