bash script – "docker run -it my_image bash" command not found

we have a list of docker images, and we are trying to see what version of node/java/mongo.. is installed inside every image, using the following bash script:

#!/bin/bash
version=""
file='images.txt'
while read line; do
        sudo docker pull $line 
        sudo docker run $line bash
        version=$(node -v)
        exit
        $version >> "version.txt"
        sudo docker image rm $line
done < $file

but we have an error on the "docker run" line which says "command not found"
the docker pull comannd works fine
we have also noticed that the while loop continues without waiting for the first docker pull to finish
and when we do the "docker run" command without the script it works fine and gets into the shell of the image.

we would appreciate any suggestions 🙂

Source: Docker Questions