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"]

最新文章

  1. web app开发之rem
  2. 解决mac安装grunt时出现[command not found]的错误
  3. Android基础类之BaseAdapter
  4. Hbase的连接池--HTablePool被Deprecated之后
  5. 本地安装gem install --local redis-stat-0.4.13.gem
  6. linux同步
  7. MongoDB入门简单介绍
  8. [AngularJS] 5 simple ways to speed up your AngularJS application
  9. E - QS Network - zoj 1586(简单)
  10. RPC通信框架——RCF介绍(替换COM)
  11. BCM策略路由交换芯片
  12. php随意笔记
  13. 深入NGINX:nginx高性能的实现原理
  14. element框架中表格的筛选功能使用说明(转载)
  15. ueditor 使用
  16. 【GMT43智能液晶模块】例程八:ADC实验——电源监控
  17. Visual Studio 10.0设置引用HalconDotNet.dll
  18. hadoop ha环境下的datanode启动报错java.lang.NumberFormatException: For input string: "10m"
  19. [EffectiveC++]item28:避免返回handles指向对象内部成分
  20. [整理]基于bootstrap的文本编辑器

热门文章

  1. Linux安装Tomcat-Nginx-FastDFS-Redis-Solr-集群——【第九集-补充-之安装jdk】
  2. 无向图的 DFS 和 BFS实现 (以邻接表存储的图)
  3. js判断上传图片文件大小,尺寸,格式
  4. CentOS 7 休眠系统
  5. Gym 102091K The Stream of Corning 2【线段树】
  6. Codeforces Round #530 (Div. 2)
  7. SQL 2016 正式版 安装过程
  8. 765. 有效的三角形.md
  9. 8. Rotate String
  10. Serializers 序列化组件