以下のような[[Bash]]スクリプトを作成し、実行する。
`waiting-connect-db.sh`
```bash
for i in $(seq 1 10); do
echo "Wait for connecting DB ( ${i}/10 )"
sleep 1
docker exec <DBコンテナ名> mysql --host localhost --port 3306 -D <DB名> -e "select 1;" >/dev/null 2>&1
# shellcheck disable=SC2181
if [[ $? -eq 0 ]]; then
echo "🤗 Connection established."
exit 0
fi
done
echo "😭 Failed to connect to database."
exit 1
```