Docker-node: Add ENTRYPOINT ["node"]

Created on 21 May 2019  Â·  9Comments  Â·  Source: nodejs/docker-node

I can't believe nobody else opened this issue already, but i couldn't find one. So sorry if this is a duplicate.

This would make usage more intuitive. Currently following throws an error:

$ docker run --rm node -e 'console.log(123)'
docker: Error response from daemon: OCI runtime create failed: container_linux.go:344: starting container process caused "exec: \"-e\": executable file not found in $PATH": unknown.

with entrypoint it works:

$ docker run --rm --entrypoint=node node -e 'console.log(123)'
123

Also it's much more intuitive that I don't have to explicitly call node again when using the node image:

docker run --rm node test.js
# vs
docker run --rm node node test.js

I mean, that's what entrypoint is made for, right? 😅
… or is there a problem with entrypoint I'm not aware of?

Most helpful comment

@tianon no worries, I had to do some brain gymnastics when implementing this.

All 9 comments

@LaurentGoderre If you look in the Dockerfiles you can see the CMD line with an entry point.

https://github.com/nodejs/docker-node/blob/master/10/alpine/Dockerfile

How does it work? I'm still figuring it out, but it's pretty crappy source code documentation for such a major project.

Here's a blog post with more detail: https://nodejs.org/en/docs/guides/nodejs-docker-webapp/

@MichaelJCole CMD and ENTRYPOINT are different. My latest PR would ideally be the best of both world where all of the possible commands would work:

  • docker run node:10
  • docker run node:10 npm install
  • docker run node node:10 script.js
  • docker run node node:10 -e 'console.log(123)'
  • docker run node:10 -e 'console.log(123)'

How does docker run node node:10 script.js work?

Probably another worthwhile exception in your script, @LaurentGoderre :sweat_smile: (files that end in .js that aren't already executable, something like what Redis does with .conf files: https://github.com/docker-library/redis/blob/6845f6d4940f94c50a9f1bf16e07058d0fe4bc4f/5.0/docker-entrypoint.sh)

@ad-si it would work if script.js is in the default image workdir.

@tianon, shouldn't that work with what I did? If it's not a know executable, it will rewrite it as node script.js

Doh yes it will, sorry for the noise 😅

@tianon no worries, I had to do some brain gymnastics when implementing this.

I believe I hit the case regarding the execution of scripts outside default image WORKDIR.

FROM node:12.16.2-alpine3.11
...
CMD [ "/usr/local/lib/code-server/out/node/entry.js"]

Running the above image results in the following error:
/usr/local/bin/docker-entrypoint.sh: exec: line 8: /usr/local/lib/code-server/out/node/entry.js: Permission denied
It runs successful if ENTRYPOINT ["node"] is added above CMD.
It'd be nice if docker-entrypoint.sh was updated to handle this case too in order to better match the behavior of node.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kmleow picture kmleow  Â·  5Comments

tigrus picture tigrus  Â·  4Comments

kingjerod picture kingjerod  Â·  5Comments

mtibben picture mtibben  Â·  3Comments

kmetsalu picture kmetsalu  Â·  5Comments