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