Repository navigation
Add ENTRYPOINT ["node"] #1039
Description
Activity
- added 5 commits that reference this issue
on May 23, 2019 @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/
Reacted by Jean-Charles LegrasReacted by Nick SchonningReacted by Jean-Charles Legras@MichaelJCole
CMDandENTRYPOINTare different. My latest PR would ideally be the best of both world where all of the possible commands would work:docker run node:10docker run node:10 npm installdocker run node node:10 script.jsdocker run node node:10 -e 'console.log(123)'docker run node:10 -e 'console.log(123)'
How does
docker run node node:10 script.jswork?Probably another worthwhile exception in your script, @LaurentGoderre 😅 (files that end in
.jsthat aren't already executable, something like what Redis does with.conffiles: 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.jsDoh yes it will, sorry for the noise 😅
@tianon no worries, I had to do some brain gymnastics when implementing this.
Reacted by Tianon GraviReacted by Tianon GraviReacted by Tianon GraviI 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 ifENTRYPOINT ["node"]is added aboveCMD.
It'd be nice ifdocker-entrypoint.shwas updated to handle this case too in order to better match the behavior ofnode.Just trying to ensure I understand what's happening in "docker-entrypoint.sh".
The docker file uses "docker-entrypoint.sh" to specify this script is what is ran when the container is started, the docker file also specifies that "node" will be the default command passed to the script. That is unless the user species arguments when running the container, in that case the default command will be replaced with what the user specifies.
Inside of the docker-entrypoint.sh the if statement is checking two things:
[ "${1#-}" != "${1}" ]- this checks to see if the argument starts with a "-"[ -z "$(command -v "${1}")" ]- this ensures that the argument is NOT a known system command.If either of those things are true, the argument is modified to append "node" in front of it.
After this the command is executed.
The purpose of this script is to provide the user flexibility in how the container is started, but one of the main benefits is to prevent awkward syntax when starting the container where the user must have "node" as their first argument.
So instead of having to run
docker run node node -e 'console.log(123)'they could simply run 'docker run node -e 'console.log(123)'Is there anything I missed? Or does this pretty much cover the purpose of the docker-entrypoint.sh?
Is there anything I missed?
Allowing system commands through without modification means that it keeps the consistency requirement of the official-images.
$ docker run -it --rm node bash $ # a shell in a node container $ # easier than having to know of and override the entrypoint $ docker run -it --rm --entrypoint bash 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:
with entrypoint it works:
$ docker run --rm --entrypoint=node node -e 'console.log(123)' 123Also 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.jsI mean, that's what
entrypointis made for, right? 😅… or is there a problem with
entrypointI'm not aware of?