Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set Docker ENTRYPOINT To NPM?

I have a Node.js project that is using npm scripts. An excerpt from package.json :

  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build-all": "./node_modules/.bin/webpack --progress --config ./webpack/client.config.js && ./node_modules/.bin/webpack --progress --config ./webpack/server.config.js",
    "web": "python -m SimpleHTTPServer 8888",
    "server" : "./node_modules/.bin/electron-spawn ./dist/server.js"
  },

I'm creating a Dockerfile for this project. I was hoping to use npm as the ENTRYPOINT for the image. In the Dockerfile I have:

ENTRYPOINT ['/usr/local/bin/npm' 'run']

when I try to start a hcontainer form the image it says it cannot find npm

root@vagrant-ubuntu-trusty-64:/home/vagrant# docker run my_image web
web: 1: web: [/usr/local/bin/npm: not found

if I start a shell in the image it looks like the npm executable is at that path

root@vagrant-ubuntu-trusty-64:/home/vagrant# docker run -i -t --entrypoint /bin/bash my_image
root@5e7362a64412:/# ls /usr/local/bin/npm
/usr/local/bin/npm
like image 615
kevzettler Avatar asked Feb 07 '16 20:02

kevzettler


1 Answers

The issue seems to be due to the single quotes in the ENTRYPOINT. Could you check if using the double quotes the issue solves?

ENTRYPOINT ["/usr/local/bin/npm", "run"]

According to the Docker guide, there are only two forms to write the ENTRYPOINT:

  1. exec form (preferred): ENTRYPOINT ["executable", "param1", "param2"]
  2. shell form: ENTRYPOINT command param1 param2
like image 128
JesusTinoco Avatar answered Sep 16 '22 14:09

JesusTinoco