Skip to content

Add ENTRYPOINT ["node"] #1039

Description

@ad-si

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?

Activity

  1. added 5 commits that reference this issue on May 23, 2019
    da595e4
    98579fb
    f2032c3
    b3052a9
    7e47b37
  2. MichaelJCole commented on May 27, 2019

    @MichaelJCole

    @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/

  3. LaurentGoderre commented on May 28, 2019

    @LaurentGoderre
    Member

    @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)'
  4. ad-si commented on May 28, 2019

    @ad-si
    Author

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

  5. tianon commented on May 28, 2019

    @tianon
    Contributor

    Probably another worthwhile exception in your script, @LaurentGoderre 😅 (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)

  6. LaurentGoderre commented on May 29, 2019

    @LaurentGoderre
    Member

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

  7. LaurentGoderre commented on May 29, 2019

    @LaurentGoderre
    Member

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

  8. tianon commented on May 29, 2019

    @tianon
    Contributor

    Doh yes it will, sorry for the noise 😅

  9. LaurentGoderre commented on May 29, 2019

    @LaurentGoderre
    Member

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

  10. mjgallag commented on Apr 14, 2020

    @mjgallag

    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.

  11. beakerandjake commented on Jul 9, 2021

    @beakerandjake

    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?

  12. yosifkit commented on Jul 9, 2021

    @yosifkit
    Contributor

    @beakerandjake

    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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions