Use a tool such as wait-for-it, dockerize, or sh-compatible wait-for. These are small wrapper scripts which you can include in your application’s image to poll a given host and port until it’s accepting TCP connections. For example, to use wait-for-it.sh or wait-for to wrap your service’s command: version: ""
services:
web:
build: .
ports:
- "80:8000"
depends_on:
- "db"
command: ["./wait-for-it.sh", "db:5432", "--", "python", "app.py"]
db:
image: postgres
Tip: There are limitations to this first solution. For example, it doesn’t verify when a specific service is really ready. If you add more arguments to the command, use the bash shift command with a loop, as shown in the next example. Alternatively, write your own wrapper script to perform a more application-specific health check. For example, you might want to wait until Postgres is definitely ready to accept commands: #!/bin/bash
# wait-for-postgres.sh set -e host="$1"
shift
cmd="$@" until psql -h "$host" -U "postgres" -c '\q'; do
>& echo "Postgres is unavailable - sleeping"
sleep
done >& echo "Postgres is up - executing command"
exec $cmd
You can use this as a wrapper script as in the previous example, by setting: command: ["./wait-for-postgres.sh", "db", "python", "app.py"]
随机推荐
-
ConcurrentModificationException(并发修改异常)的解决
[异常解释] ConcurrentModificationException:当方法检测到对象的并发修改,但不允许这种修改时,抛出此异常.[产生的原因] 迭代器是依赖于集合而存在的,在判断成功后,集合 ...
-
JavaSE| 集合
集合 l Collection 层次结构中的根接口.Collection 表示一组对象,这些对象也称为 collection 的元素.一些 collection 允许有重复的元素,而另一些则不允许. ...
-
ContentProvider插件化解决方案
--摘自<android插件化开发指南> 1.当要传输的数据量大小不超过1M的时候,使用Binder:数据量超过1M时,Binder就搞不定了,需要ContentProvider 2.Co ...
-
POJ 1988 Cube Stacking 【带权并查集】
<题目链接> 题目大意: 有几个stack,初始里面有一个cube.支持两种操作: 1.move x y: 将x所在的stack移动到y所在stack的顶部. 2.count x:数在x所 ...
-
Logstash读取Kafka数据写入HDFS详解
强大的功能,丰富的插件,让logstash在数据处理的行列中出类拔萃 通常日志数据除了要入ES提供实时展示和简单统计外,还需要写入大数据集群来提供更为深入的逻辑处理,前边几篇ELK的文章介绍过利用lo ...
-
2018ddctf wp
杂项 第一题:颜文字 看过以后开始没思路:后来有师傅说是十六进制 我就上网百度了一下http://tieba.baidu.com/p/3717777553 但是不可能是完全十六进制啊,毕竟出题人很羞涩 ...
-
栈 VS 队列
linkStack.javalinkQueue.java程序强调栈和队列是概念上的实体,独立于它们的具体实现.用数组或者是用链表实现栈都是一样的.栈的重要性在于它的push()操作和pop()操作.以 ...
-
scrapy 安装
windows 1.wheelpip install wheel2.lxmlhttp://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml3.PyOpensslhttp ...
-
手机端input获取焦点弹出键盘时挡住input解决方案
问题重现 原始页面:页面中有header.main.footer三部分,其中 header 和 footer 通过 position: fixed; 定位在浏览器顶部和底部. 其中,footer 中有 ...
-
Codeforces.578E.Walking(构造)
题目链接 \(Description\) 给定一个长为\(n\)的足迹序列(只包含\(L,R\)两种字符),你需要\(LRLRLR...\)这样交替在\(L\)和\(R\)上走(第一步可以选择\(L\ ...