Docker-compose check if mysql connection is ready

后端 未结 9 2151
一个人的身影
一个人的身影 2020-11-27 13:40

I am trying to make sure that my app container does not run migrations / start until the db container is started and READY TO accept connections.

So I decided to use

9条回答
  •  心在旅途
    2020-11-27 14:01

    I had the same problem, I created an external bash script for this purpose (It is inspired by Maxim answer). Replace mysql-container-name by the name of your MySQL container and also password/user is needed:

    bin/wait-for-mysql.sh:

    #!/bin/sh
    until docker container exec -it mysql-container-name mysqladmin ping -P 3306 -proot | grep "mysqld is alive" ; do
      >&2 echo "MySQL is unavailable - waiting for it... 

提交回复
热议问题