一些有用的命令行实用程序,等待docker compose文件中声明的所有服务都启动并运行。
docker-compose-wait的Python项目详细描述
Docker编写等待
一些有用的脚本,等待docker compose文件中声明的所有服务都启动并运行。
此脚本使用Docker1.12之后提供的运行状况检查机制。如果您的服务具有已配置的运行状况检查,则在进行docker-compose up -d
之后,您只需调用此脚本,让它等待您的所有服务运行状况都得到修复。如果它们都是healthy
,则返回0
;如果其中任何一个是unhealthy
(或Down
),则返回-1。
例如,在连续集成或其他情况下,当您只想等到部署堆栈后再执行其他操作时,此脚本可能非常有用。
请注意,此脚本对依赖项启动顺序没有任何作用。关于这个问题,请参见official documentation。
安装
pip install docker-compose-wait
此实用程序需要Python2.7或Python>;=3.3。它还支持1.10版的docker-compose
。
用法
usage: docker-compose-wait.py [options]
Wait until all services in a docker-compose file are healthy. Options are
forwarded to docker-compose.
optional arguments:
-h, --help show this help message and exit
-f FILE, --file FILE Specify an alternate compose file (default: docker-
compose.yml)
-p PROJECT_NAME, --project-name PROJECT_NAME
Specify an alternate project name (default: directory
name)
-w, --wait Wait for all the processes to stabilize before exit
(default behavior is to exit as soon as any of the
processes is unhealthy)
-t TIMEOUT, --timeout TIMEOUT
Max amount of time during which this command will run
(expressed using the same format than in docker-
compose.yml files, example: 5s, 10m,... ). If there is
a timeout this command will exit returning 1.
(default: wait for an infinite amount of time)
基本上可以简单到:
docker-compose-wait
docker-compose-wait
的行为类似于docker-compose
子命令。它将转发通常的docker-compose
命令行参数。如果您以前通过引用标准的docker-compose.yml
文件来运行docker-compose up -d
,那么上面的命令可以正常工作。如果您正在使用其他文件进行配置,请使用:
docker-compose-wait -f <path_to_yaml_file> -f <path_to_other_yaml_file> ...