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. 071 SparkStreaming与SparkSQL集成

    1.说明 虽然DStream可以转换成RDD,但是如果比较复杂,可以考虑使用SparkSQL. 2.集成方式 Streaming和Core整合: transform或者foreachRDD方法 Cor ...

  2. Kafka命令行操作及常用API

    一.Kafka命令行操作 1.查看当前集群已存在的主题 bin/kafka-topic.sh --zookeeper hd09-01:2181 --list 2.创建主题 bin/kafka-topi ...

  3. iOS9 中 alertView 的使用

    "UIAlertView is deprecated. Use UIAlertController with a preferredStyle of UIAlertControllerSty ...

  4. SpringBoot使用LomBok

    Lombok是什么?它是一个能帮我们消除那些必须要写但是重复的代码,比如setter,getter,构造函数之类的方法. 首先先简单说一下idea安装lombok,有2种方法: 1.直接从http:/ ...

  5. XamarinSQLite教程下载安装SQLite/SQL Server Compact Toolbox

    XamarinSQLite教程下载安装SQLite/SQL Server Compact Toolbox SQLite/SQL Server Compact Toolbox是一个Visual Stud ...

  6. spring 4.1 xml配置头部信息 maven配置信息

    <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://w ...

  7. css的基本定位机制

    分为三种:普通流.浮动.绝对定位 普通流:默认,html文档的排列顺序块级从上到下(垂直距离由margin-top.margin-bottom决定):行内元素在一行中从左到右(由margin-left ...

  8. Shell脚本笔记(一)一些零碎的基础知识

    一些零碎的基础知识 一.认识Shell脚本 一)相关概念 Shell是一种命令解释器,作用是按次序执行(遇到子脚本,先执行子脚本的命令)用户输入的命令和程序. Shell脚本语言是弱类型语言,与其他脚 ...

  9. 潭州课堂25班:Ph201805201 django 项目 第十八课 前台 注解 (课堂笔记)

    在静态文件 js/user上当下,的 auth.js 文件中 $(function () { let $username = $('#user_name'); // 选择id为user_name的网页 ...

  10. [CF536D]Tavas in Kansas

    [CF536D]Tavas in Kansas 题目大意: 一张\(n(n\le2000)\)个点,\(m(m\le10^5)\)条边的无向带权连通图(权值可以为负).A.B两人分别在\(s,t\)点 ...