6

To get a node version - I expect to run the following:

node --version

I'm running the following with docker:

docker run node:4-onbuild -v

I get this:

docker: Error response from daemon: Container command '--version' not found or does not exist..

My question is: How to get version of node from docker container?

Community
  • 1
  • 1
hawkeye
  • 34,745
  • 30
  • 150
  • 304
  • 1
    Could you try `docker run -it --rm node /bin/bash -c 'node --version'` – Jayaram Mar 08 '17 at 12:41
  • your command `docker run node:4-onbuild -v` does launch a node:4 docker container, and tries to launch the command `-v` which is not a valid bash command, see Kunkka's answer – user2915097 Mar 08 '17 at 13:06

2 Answers2

5

you need to specifically ask docker to run -v within the node container like below

docker run -it --rm node /bin/bash -c 'node --version'
Jayaram
  • 6,276
  • 12
  • 42
  • 78
  • 3
    In case one uses `node:alpine` or other distributions who have no `bin/bash` available, you can use `docker run -it --rm node:alipne node`. It will start node console with version info in the first line. – Tzahi Leh Aug 11 '20 at 08:42
0

you can simply type "docker run node -v"

  • 1
    You still need to specify the image, so we could do something like you mentioned: `docker run -it node:latest /usr/local/bin/node -v` or with short form: `docker run -it node node -v` – minus one May 20 '23 at 14:14
  • 1
    Try to give explanation to your answer, people also understand why one or other solution works. – minus one May 20 '23 at 14:21
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 20 '23 at 14:45