简体   繁体   中英

How to wait for docker-entrypoint-initdb.d to load DB in Shell Script/Bash?

I wrote a shell script to rebuild a test DB and load dumps.sql on docker-entrypoint-initdb.d and then execute phpunit tests.

docker-compose stop mysql
sudo rm -Rf ~/.laradock/data/mysql
docker-compose up --force-recreate --build -d mysql
docker-compose up -d nginx
docker-compose exec workspace phpunit

This is working fine. However the third line executes the dumps are loaded in the background and takes sometime to load. When the last line is executed the DB dumps are still beeing loaded

I have to wait around 1 or 2 minutes. What I'm loking for is a solution like: - A sleep between 2 shell commands OR(to a better code) - Make the last line wait the fully execution of the dump loading.

How can i know that the docker-entrypoint-initdb.d, called when the container is rebuilt, is fully loaded? To use in the shell script.

Hmm in bash commands if on new line are executed after each one and other completes. -d option for docker-compose probably sends the process to background. So in that case try to use wait command which waits for all child processes:

docker-compose stop mysql
sudo rm -Rf ~/.laradock/data/mysql
docker-compose up --force-recreate --build -d mysql
docker-compose up -d nginx
wait
docker-compose exec workspace phpunit

If that does not help you may try also this removing -d option and send processes to background natively by bash & :

docker-compose stop mysql
sudo rm -Rf ~/.laradock/data/mysql
docker-compose up --force-recreate --build mysql &
docker-compose up nginx &
wait
docker-compose exec workspace phpunit

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM