How do I know when my docker mysql container is up and mysql is ready for taking queries?

后端 未结 14 1030
猫巷女王i
猫巷女王i 2020-11-30 22:33

I am deploying a few different docker containers, mysql being the first one. I want to run scripts as soon as database is up and proceed to building other containers. The sc

14条回答
  •  日久生厌
    2020-11-30 23:25

    Some times the problem with the port is that the port could be open, but the database is not ready yet.

    Other solutions require that you have installed the mysql o a mysql client in your host machine, but really you already have it inside the Docker container, so I prefer to use something like this:

    while ! docker exec mysql mysqladmin --user=root --password=root --host "127.0.0.1" ping --silent &> /dev/null ; do
        echo "Waiting for database connection..."
        sleep 2
    done
    

提交回复
热议问题