Marcin
Marcin

Reputation: 243

Bower dependicies with postinstall on Docker

It is possible to install bower dependicies using postinstall in package.json on docker with docker-compose?

package.json file:

   {
      "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"]

docker-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

And after use docker-compose up application works fine but missing bower dependicies, can I fix that?

P.S

This I found in console after docker-compose up:

npm WARN lifecycle [email protected]~postinstall: cannot run in wd %s %s (wd=%s) [email protected] node ./node_modules/bower/bin/bower install /application

Thanks

Upvotes: 1

Views: 1165

Answers (1)

Yi Kai
Yi Kai

Reputation: 640

Change node ./node_modules/bower/bin/bower install to bower install --allow-root in postinstall script. The --allow-root is to prevent you from permission errors.

Or you can remove the postinstall script and add RUN bower install --allow-root after RUN npm install in the Dockerfile.

And bower requires git to work, you have to install git first in your Dockerfile.

Upvotes: 1

Related Questions