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
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...