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:

  • Azure App Service + Docker Autodeploy?
  • Jenkins and docker plugin: Problems to launch container
  • Can't Access Spring Boot API in docker container
  • Separate CI workflows for multiple applications within same Git repo
  • gitlab CI build runs on my local docker container
  • CircleCI './docker-compose.yml' service 'version' doesn't have any configuration options
  • 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.


  • How to reach a linked service in docker-compose?
  • docker compose won't mount the external volume
  • ServiceStack Docker architecture
  • Kalabox Drush failins. Can I run a bash shell in the created Docker container instead?
  • Docker returning same kernel version for 10.04 and 10.10
  • Unable to share C drive on Docker for Windows
  • 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.