在脚本执行完毕后,Docker容器不会停止移动

我们有一个Docker服务器“Docker版本17.03.0-ce,build 60ccb22”。 我们有大约10名工人,他们每个人都执行一个非常简单的任务,需要几秒钟才能完成并退出。 我们决定每个人都会启动一个docker集装箱,当脚本结束时,集装箱被停止并被移走。 更重要的是,crontabs处理运行因此,我们为每个使用标志–rm和-d实例化容器的worker创build了一个bash脚本,并启动bin /文件夹中的脚本文件

#! /bin/sh f=`basename $0` workerName=${f%.*} \\name of the bash script without the part after the . //We link with the Docker host the folder of the worker and a log file that is going to be used for monitoring from outside the container. docker run --rm -d --name $workerName -v `cat /mnt/volume-fra1-05/apps/pd-executioner/master/active_version`:/var/www/html -v /mnt/volume-fra1-06/apps/$workerName.log:/var/www/html/logs/$workerName.log iqucom/php-daemon-container php bin/$workerName echo `date` $0 >> /var/log/crontab.log 

因此,我们为每个使用标志–rm和-d实例化容器的工人创build了一个bash脚本,并且还启动了bin /文件夹中的脚本文件。 所有的工作人员都非常相似的结构和代码,非常简单,没有大的代码差异。 但是,我们经历了如下的行为:一些容器(每次随机)拒绝停止,甚至在很多小时之后都被移除。 在容器内部, php bin/$workerName进程仍在运行PID 1.没有任何东西像代码中的无限循环,可能会阻止脚本的完成。 它随机发生,仍然无法find一个模式。 你有什么想法,为什么这可能会发生?

所以这可能是一些与你的PHP脚本卡住的问题。 但既然你确定它假设在假设240secs后超时,那么你应该可以改变你的容器命令

docker run –rm -d –name $ workerName -v cat /mnt/volume-fra1-05/apps/pd-executioner/master/active_version :/ var / www / html -v / mnt / volume-fra1-06 /apps/$workerName.log:/var/www/html/logs/$workerName.log iqucom / php-daemon-container timeout 240 php bin / $ workerName

这将确保任何卡住的容器在超时后退出,如果它不自行退出