[英]Why do node_modules keep disappearing from docker after build?
I'm mimicking the setup found here https://github.com/mjhea0/node-docker-workflow . 我模仿的是这里的设置https://github.com/mjhea0/node-docker-workflow 。 Using docker-compose to link 2 docker containers (node, redis).
使用docker-compose链接2个docker容器(节点,redis)。
Here's the circle ci file: 这是circ ci文件:
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: 这是我的节点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. 测试一直在失败,因为找不到
chai
。 This is due to node_modules
disappearing once the build is complete. 这是由于构建完成后
node_modules
消失了。
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. 从字面上看,在Circle.yml文件的这两个步骤之间,通过npm install安装了node_modules,然后在运行npm test命令时它们消失了。
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.
正如我刚开始使用Docker一样,有人可以(用外行的话)相当彻底地解释我上面使用的存储库有什么问题,以及如何解决它。
Thanks! 谢谢!
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. 要解决此问题,只需删除
-d
,以便下一个命令在容器内运行。
docker-compose run --no-deps node
Simple. 简单。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.