03/06/2018 - DOCKER, MYSQL
Docker ortamında veritabanının çalışmasının zaman aldığını biliyoruz. Bu nedenle herhangi bir sorgunun çalıştırılmasından önce veritabanının durumunu öğrenmek isterseniz, aşağıdaki örneği kullanabilirsiniz.
version: '3'
services:
mysql:
build:
context: ./docker/mysql
...
volumes:
- ./docker/mysql/init.sh:/docker-entrypoint-initdb.d/init.sh
FROM mysql:5.7.22
COPY init.sh /docker-entrypoint-initdb.d/init.sh
#!/bin/bash
echo "Checking if the database is up ..."
while ! mysqladmin ping -h"localhost" --silent; do
echo "Waiting for the database to come up ..."
sleep 2
done
echo "Database is up ..."
# Run an example query
mysql -u root -proot -e "USE mysql;"
$ docker-compose up -d
...
mysql_1 | Checking if the database is up ...
mysql_1 | Waiting for the database to come up ...
mysql_1 | Waiting for the database to come up ...
mysql_1 | Database is up ...
...