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:

  • Permission error when deploying Docker app from CI server to Heroku
  • Run maven command from docker image
  • Continuous integration - deploying only changed components
  • Why doesn't a command that works inside a docker container work from outside via docker run?
  • Adding bind-mounts to the containers for running a task in concourse
  • Rebuild and ReRun a DockerContainer
  • machine:
      services:
        - docker
    
    dependencies:
      override:
        - sudo pip install -U docker-compose
    
    test:
      override:
        - 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.

    test:
      override:
        - 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.

    Thanks!

  • Secure Consul with SSL does not work
  • two applications used in docker swarm
  • Docker container without ipv4 address
  • How to remove development dependencies in production docker images
  • ENV[“VARIABLE”].encoding return #<Encoding:ASCII-8BIT> on production when being assigned a unicode string
  • manage containers from another container, docker
  • 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

    Simple.

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