docker-compose 启动顺序

通过 depends_on 选项是同时启动,但是会导致比如mysql启动的慢,web启动的快,连接过去会有暂时的报错,想解决就写个启动脚本,指明某些服务的sleep时间。

```sh
#!/bin/bash
# wait-for-postgres.sh

set -e

host="$1"
shift
cmd="$@"

until psql -h "$host" -U "postgres" -c '\l'; do
  >&2 echo "Postgres is unavailable - sleeping"
  sleep 1
done

>&2 echo "Postgres is up - executing command"
exec $cmd

# 参考文档
https://docs.docker.com/compose/startup-order/

你可能感兴趣的:(docker-compose 启动顺序)