Checking if the MySQL service of a Docker container is ready

Published on 2020-09-03 • Modified on 2020-09-03

In the previous snippet, we saw how to do it for a Postgres service; now it's for MySQL. The process is similar, but there is a slight difference as there is no equivalent of the pg_isready command for MySQL. Therefore we have to grep the output of the mysqladmin ping command to check if the service is "alive". Change the sb-db parameter for the name of your MySQL docker container. Check out my full Makefile to see how I am calling this script in the run target.

until docker container exec -it strangebuzz-db-1 mysqladmin ping -P 3306 -proot | grep "mysqld is alive" ; do
  >&2 echo "MySQL is unavailable - waiting for it... 😴 ($seconds)"
  sleep 1
  seconds=$(expr $seconds + 1)
sleep 1

 More on Stackoverflow   Read the doc  Random snippet

  Work with me!