[英]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. 我编写了一个Shell脚本来重建测试数据库,并在docker-entrypoint-initdb.d上加载dumps.sql,然后执行phpunit测试。
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. 我必须等待大约1或2分钟。 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.
我想要的是一种解决方案,例如:-在2个Shell命令之间进行睡眠或(以获取更好的代码)-使最后一行等待转储加载的完全执行。
How can i know that the docker-entrypoint-initdb.d, called when the container is rebuilt, is fully loaded? 我怎么知道重建容器时调用的docker-entrypoint-initdb.d已满载? To use in the shell script.
在shell脚本中使用。
Hmm in bash commands if on new line are executed after each one and other completes. bash命令中的Hmm(如果在新行中)在彼此完成之后执行。
-d
option for docker-compose probably sends the process to background. docker-compose的
-d
选项可能会将进程发送到后台。 So in that case try to use wait
command which waits for all child processes: 因此,在这种情况下,请尝试使用
wait
所有子进程的wait
命令:
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 &
: 如果那没有帮助,您也可以尝试使用该删除
-d
选项,并通过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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.