简体   繁体   English

bash 脚本 - 找不到“docker run -it my_image bash”命令

[英]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:我们有一个 docker 镜像列表,我们正在尝试使用以下 bash 脚本查看每个镜像中安装了哪个版本的 node/java/mongo..

#!/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.但是我们在“docker run”行上有一个错误,它说“找不到命令”docker pull 命令工作正常我们还注意到 while 循环继续而不等待第一个 docker pull 完成,当我们执行“docker pull”运行”命令没有脚本它工作正常并进入图像的外壳。

we would appreciate any suggestions :)我们将不胜感激任何建议:)

I'm guessing you probably mean我猜你可能是说

#!/bin/bash
while read -r line; do
        sudo docker pull "$line" 
        sudo docker run -it --rm "$line" node -v
done <images.txt >version.txt

... but code which doesn't do what you want to do is a terrible way to tell us what you actually want to do. ......但是代码不能做你想做的事情是告诉我们你真正想做的事情的可怕方式。 This will run node -v inside each container, where the -it option is crucial for getting output on standard output, and --rm takes care of what (I'm guessing) you were doing with a separate rm .这将在每个容器内运行node -v ,其中-it选项对于在标准输出上获取输出至关重要,而--rm负责处理(我猜)你用单独的rm做什么。 This still obviously depends on what exactly is in the input file.这显然仍然取决于输入文件中的确切内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM