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:

  • DockerFile / Switch from ubuntu:latest to alpine:3.3
  • Crash during startup with network share for gitlab container
  • How do I run Cosmos DB Emulator on Docker for Windows?
  • How to get remote access to a private docker-registry?
  • Hazelcast in multinode docker environments with TCPIP
  • Docker cluster on multiple host
  • 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"
    

    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:

    /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)
    

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

  • Docker Swarm - Network Overlay not connecting all containers
  • What are the differences between a VM image and a Docker image? [duplicate]
  • docker-compose run returns /bin/ls cannot execute binary file
  • How to let Docker containers broadcast their IP addresses or hostnames to each other?
  • Cassandra on Mesos Container
  • Docker: One image per user? Or one image for all users?
  • 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

    node:
      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.