How to get version of node from docker container?
Asked Answered
D

3

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?

Dashiell answered 8/3, 2017 at 12:31 Comment(2)
Could you try docker run -it --rm node /bin/bash -c 'node --version'Kind
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 answerBowls
K
6

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'
Kind answered 8/3, 2017 at 13:58 Comment(1)
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.Claptrap
M
1

you can simply type "docker run node -v"

Mikael answered 20/5, 2023 at 11:7 Comment(4)
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 -vKazbek
Try to give explanation to your answer, people also understand why one or other solution works.Kazbek
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.Thy
node is the image that is going to run. docker will translate this to docker.io/library/node:latest. ... You can find the image and what the latest tag points at if you visit hub.docker.com/_/node. The latest tag is a link to the Dockerfile on github and there you can see at the bottom, the definition CMD [ "node" ] The image "node" will by default run "node" the command. It wil pull over 1GB of node image and the container is not automatically cleaned up if you don't set --rmPeen
S
0

You can use the following command to fetch node version running on a specific container.

docker exec <container-name> node -v
Submit answered 15/8 at 13:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.