我一直在使用 docker images 设置 Jenkins 管道。现在我需要运行各种服务,如 MySQL、Redis、Memcache、Beanstalkd 和 Elasticsearch。要等待作业直到 MySQL 准备就绪,我使用以下命令:
sh "while ! mysqladmin ping -u root -h mysqlhost ; do sleep 1; done"
sh 'echo MySQL server is up and running'
mysqlhost
是我为容器提供的主机名。同样,我需要检查并等待 Redis、Memcached、Beanstalkd 和 Elasticsearch
。但是对这些服务的 ping 操作并不像 MySQL
那样有效。我该如何实现?
最佳答案
Docker docs提到这个脚本来管理容器准备检查:https://github.com/vishnubob/wait-for-it
我也使用与 Alpine 兼容的这个: https://github.com/eficode/wait-for
关于linux - 如何等到服务准备好,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51022611/