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:

  • Error running gitlab-ci.yml script under Alpine Docker based Image
  • how to make docker logs in java
  • How to get Docker to run on a Windows System behind a corporate firewall?
  • How upgrade a docker image without creating new image?
  • How to make container wait for other container in Docker Compose
  • Can't get clipboard forwarding working, while being in Docker under SSH
  • 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.

  • Syntax Error: Multiline bash command in dockerfile RUN statement
  • Use Docker, Gunicorn, Nginx in django development environment but can only see nginx welcome page?
  • Is it possible to run mutliple docker machines within one virtual machine (virtualbox)?
  • Docker Compose only starts one container
  • how to pass a --login into docker build
  • Packer provisioning docker with chef-solo gets node name not found error
  • 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.