Bower依赖于Docker上的postinstall

时间:2017-07-07 03:18:39

标签: node.js docker bower

可以使用docker-compose在docker的package.json中使用postinstall安装bower dependicies吗?

package.json文件:

   {
      "name": "mongocrud",
      "version": "0.0.0",
      "private": true,
      "scripts": {
        "start": "node ./config/server.js",
        "postinstall": "node ./node_modules/bower/bin/bower install",
        "test": "mocha"
      },
      "dependencies": {
        //dependicies
      }
    }

Dockerfile:

FROM node:7.7.2-alpine

WORKDIR /application

COPY package.json .

COPY bower.json .

COPY .bowerrc .

RUN npm install -g bower

RUN npm install

COPY . .

EXPOSE 3000

CMD ["npm", "start"]

搬运工-compose.yml:

version: '3'

services:
    mongodb:
        image: mongo:3.4.4
        command: mongod
        container_name: mongo-container
        ports:
            - 27017:27017

    express:
         build: .
         container_name: express-container
         ports:
            - 3000:3000
         working_dir: /application

         links:
            - mongodb
         command: npm start

使用docker-compose up应用程序工作正常但缺少bower依赖,我能解决吗?

P.S

这是我在docker-compose up后在控制台中找到的:

npm WARN lifecycle mongocrud@0.0.0~postinstall: cannot run in wd %s %s (wd=%s) mongocrud@0.0.0 node ./node_modules/bower/bin/bower install /application

由于

1 个答案:

答案 0 :(得分:0)

在postinstall脚本中将node ./node_modules/bower/bin/bower install更改为bower install --allow-root--allow-root是为了防止您出现权限错误。

或者您可以删除postinstall脚本并在RUN bower install --allow-root之后在Dockerfile中添加RUN npm install

bower需要git才能工作,你必须先在你的Dockerfile中安装git。