使用docker和docker-compose运行npm install和bower install

时间:2015-08-16 20:13:16

标签: node.js docker npm bower docker-compose

我正在尝试将docker与节点图像一起使用,以便运行bower installdocker-compose.yml

以下是我node: image: node:0.10.40 volumes: - ./package.json:/package.json - .bowerrc:/.bowerrc - ./bower.json:/bower.json - ./build/npm.tmp/node_modules:/node_modules - ./build/npm.tmp/bignibou-client/src/bower_components:/bignibou-client/src/bower_components command: bash -c "npm install && bower install" ports: - "8888:8888" 的相关部分:

node_1          | bash: bower: command not found
bignibousite_node_1 exited with code 127

不幸的是,我从节点收到以下错误:

  "scripts": {
    "postinstall": "/node_modules/bower/bin/bower install"
  }

表示命令未正确解释。

我也尝试在package.json中使用post-script,如下所示:

.bowerrc

这是我的{ "json": "bower.json", "directory": "bignibou-client/src/bower_components" }

npm install

如果没有bower安装,bower install运行正常。我真的无法工作node_1 | npm WARN cannot run in wd bignibou-client@0.1.0 /node_modules/bower/bin/bower install (wd=/)

有人可以帮忙吗?

修改:上面的安装后脚本从节点中给出了这个错误:

docker run -it --rm \
   -v ./package.json:/package.json  \
   -v .bowerrc:/.bowerrc \
   -v ./bower.json:/bower.json  \
   -v ./build/npm.tmp/node_modules:/node_modules  \
   -v ./build/npm.tmp/bignibou-client/src/bower_components:/bignibou-client/src/bower_components \
   digitallyseamless/nodejs-bower-grunt bower install

编辑2 :我尝试了Alexis建议的解决方案,即使用现有图片,但我尝试指定本地bower.json等,如下所示:

/usr/local/lib/node_modules/bower/node_modules/bower-config/node_modules/graceful-fs/polyfills.js:224
      throw er
            ^
Error: EISDIR, illegal operation on a directory
    at Error (native)
    at Object.fs.readSync (fs.js:552:19)
    at Object.fs.readSync (/usr/local/lib/node_modules/bower/node_modules/bower-config/node_modules/graceful-fs/polyfills.js:218:23)
    at Object.fs.readFileSync (fs.js:384:28)
    at /usr/local/lib/node_modules/bower/node_modules/bower-config/lib/util/rc.js:75:27
    at Array.forEach (native)
    at json (/usr/local/lib/node_modules/bower/node_modules/bower-config/lib/util/rc.js:74:14)
    at rc (/usr/local/lib/node_modules/bower/node_modules/bower-config/lib/util/rc.js:31:9)
    at Config.load (/usr/local/lib/node_modules/bower/node_modules/bower-config/lib/Config.js:14:20)
    at Function.Config.read (/usr/local/lib/node_modules/bower/node_modules/bower-config/lib/Config.js:49:19)

我收到此错误:

fadein

我不知道为什么我会这样做以及如何解决这个问题。

1 个答案:

答案 0 :(得分:2)

我认为您应该在图片中全局安装bower

创建此Dockerfile

FROM node:0.10.40
RUN npm install -g bower

并在docker-compose.yml文件中引用它

node:
  build: .  // <= Path to the folder containing the Dockerfile

...

否则,dockerhub digitallyseamless/nodejs-bower-grunt上有一个已经提供它的热门图片。