Starting a docker container with a node.js app produces error; complains about PATH

StackOverflow https://stackoverflow.com//questions/24048002

  •  21-12-2019
  •  | 
  •  

I've been banging my head against the wall on this one for a while and need a little help.

I have a docker container built from a Dockerfile. When I try to run that container (either interactively [-i] or detached [-d]), it produces the following error:

2014/06/04 21:17:40 exec: "node": executable file not found in $PATH

This is how I'm trying to start the container (made generic for security reasons):

sudo docker run -i -t -p port:port containername:containerversion node /path/to/node/app/nodeapp.js

What is troublesome and confusing is that when I run the container without that command appended, I am able to cd into the directory /path/to/node/app and run:

node nodeapp.js

This works fine for me. Additionally, when I compare the contents of the "which node" command and the output of "echo $PATH", I see that everything is kosher. So, why in the heck does this refuse to acknowledge that I am its master and it should do what I say?

有帮助吗?

解决方案

nodejs should be work.

I don't know why, but it installed named nodejs not node in my case.

其他提示

In your Dockerfile, ensure your WORKDIR is set and the CMD instruction looks like one of the following:

CMD ["npm", "start"] or

CMD ["node", "nodeapp.js"]

Try running it like this:

sudo docker run -i -t -p port:port containername:containerversion /path/to/node/bin/node /path/to/node/app/nodeapp.js

It must be possible to add it to your path, but I don't know how. But even if you could, it still makes sense to use full path like above, because you wouldn't accidentally run a different node this way.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top