'How can I list docker container names along with node version

I was wondering if there is a smart way to output all docker names along with the version of node.js they are running for the containse/service.

I can run;

docker ps --format '{{.Names}}'

...to get a list of all names, but then I'm stuck running;

docker exec <NAME goes HERE> node -v

...for each item NAME one-by-one to find out the NODE.JS version linked to it (which is somewhat tedious and time consuming even with my fast fingers and copy/paste tool)

Is there a way of combining these two commands into one to output name and node version? Or are we into a linux-scripting-type territory here?!

Please note; I've found these commands via googling and only really understand the docker basics like stop/start/listing stuff out...

Many thanks in advance for any information or answers received!



Solution 1:[1]

A think a simple bash script should be easy enough. I don't have docker installed, but you can probably tweak the approach below?

Create script.sh and grant it execute permissions.

from the terminal

nano script.sh #paste in script below"

for container in `docker ps -q`; do 
  # show the name of the container
  docker inspect --format='{{.Name}}' $container;
  # run the command
  docker exec {{.Name}} node -v
done

make the script executable

chmod u+x script.sh

Run the script

./script.sh

Should see the node version printed to tty

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Max888