简体   繁体   English

为什么node_modules在构建后仍会从Docker中消失?

[英]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.

相关问题 将 node_modules 导入本地文件而不是在构建后从 node_modules 导入? - Import node_modules to local files instead of importing from node_modules after build? 如何在 Docker 构建中缓存 node_modules? - How to cache node_modules on Docker build? 减少 node_modules 后 node_modules 出错 - Error with node_modules after I decreased the node_modules 忽略Docker卷中的每个`node_modules` - Ignoring every `node_modules` in a docker volume 你如何从 node_modules 调用函数 - How do you call functions from node_modules 模块构建失败(来自./node_modules/craco-less/node_modules/less-loader/dist/cjs.js): - Module build failed (from ./node_modules/craco-less/node_modules/less-loader/dist/cjs.js): 模块构建失败(来自./node_modules/@nuxt/webpack/node_modules/babel-loader/lib/index.js): - Module build failed (from ./node_modules/@nuxt/webpack/node_modules/babel-loader/lib/index.js): Angular 2导入node_modules未添加到构建 - Angular 2 importing node_modules not adding to build SystemJS无法从node_modules加载模块 - SystemJS not loading modules from node_modules 如何在docker构建期间的yarn / npm安装期间缓存node_modules以获取未更改的package.json - How to cache node_modules for unchanged package.json during yarn / npm install during docker build?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM