Reputation: 24697
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
:
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 [email protected] /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.
Upvotes: 2
Views: 4370
Reputation: 3993
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.
Upvotes: 3