linux - 如何等到服务准备好

标签 linux shell docker jenkins sh

我一直在使用 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/

相关文章:

linux - ClearCase 用户的 SVN。如何使用?

linux - Bower:未找到命令

shell - 使用curl下载文件时如何保留远程文件名

linux - 如何在 Bash 中将字符串转换为整数?

docker - 使用 Windows 容器(而不是 Linux 容器)时如何在 Docker for Windows 10 中创建数据卷

docker - 版本 `GLIBC_2.29' 未找到

c - 使用 syslog.h 将自定义时间戳写入 syslog

linux - execv() 和 fork() 的时间浪费

c - C 中的虚拟 Shell 在关闭外部进程后会出现问题

当我重定向输出时,Python 程序不会在 docker 容器中的 shell 脚本中运行