Using docker and docker-compose in order to run npm install and bower install

I am trying to use docker with a node image in order to run npm install and bower install.

Here is the relevant portion from my docker-compose.yml:

  • Can’t link to MS Azure account
  • Wrap origin public Dockerfile to manage build args, etc
  • Will single docker container scale automatically on Amazon's EC2?
  • Unable to access Docker Nanoserver container web app
  • runners: How do I install and run software from an external repos?
  • Docker container doesnot reflect changes on machines other than it was created
  • node:
      image: node:0.10.40
       - ./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"
       - "8888:8888"

    Unfortunately I get the following error from node:

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

    Indicating the command was not interpreted properly.

    I have also tried using a post-script in my package.json as follows:

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

    Here is my .bowerrc:

        "json": "bower.json", "directory": "bignibou-client/src/bower_components"

    Without the bower install, the npm install is run OK. It is really the bower install that I cannot get to work.

    Can anyone please help?

    edit: the postinstall script above gives me this error from node:

    node_1          | npm WARN cannot run in wd bignibou-client@0.1.0 /node_modules/bower/bin/bower install (wd=/)

    edit 2: I tried the solution suggested by Alexis i.e. using an existing image but I tried to specify a local bower.json, etc. as follows:

    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

    I get this error though:

          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 (/usr/local/lib/node_modules/bower/node_modules/bower-config/lib/Config.js:49:19)

    I am not sure why I get this and how to sort it out.

  • How to substitute variable value in “docker run” command
  • Copy or scp files to /var/lib/boot2docker for boot2docker VM managed by docker-machine
  • how to save a docker redis container
  • What to do with pid files in a docker container
  • Installing pure-ftpd in docker (Debian wheezy), error 421
  • How to load LDAP docker container data on startup
  • One Solution collect form web for “Using docker and docker-compose in order to run npm install and bower install”

    I think you should install bower globally in your image

    Create this Dockerfile:

    FROM node:0.10.40
    RUN npm install -g bower

    And reference it in the docker-compose.yml file

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

    Otherwise, there is a popular image on dockerhub digitallyseamless/nodejs-bower-grunt that already provides it.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.