简体   繁体   English

如何等待docker-entrypoint-initdb.d在Shell脚本/ Bash中加载数据库?

[英]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.

相关问题 docker 权限被拒绝 mysql 映像中的 shell 脚本放置在 docker-entrypoint-initdb.d - docker permission denied for shell script in mysql image placed at docker-entrypoint-initdb.d 无法使用 mysql docker 容器在 docker-entrypoint-initdb.d 中创建数据库 - Can't create db in docker-entrypoint-initdb.d with mysql docker container MySql Docker /docker-entrypoint-initdb.d 编码错误 - MySql Docker /docker-entrypoint-initdb.d wrong Encoding 为什么我的 docker-entrypoint-initdb.d 脚本(在 docker-compose.yml 中指定)没有被执行来初始化一个新的 MySQL 实例? - Why isn't my docker-entrypoint-initdb.d script (as specified in docker-compose.yml) executed to initialize a fresh MySQL instance? sql转储是否被加密到docker容器docker-entrypoint-initdb.d中? - Are sql dumps moved into docker container `docker-entrypoint-initdb.d` encrypted? docker-compose up invalid mode /docker-entrypoint-initdb.d/ - 无法为服务数据库创建容器 - docker-compose up invalid mode /docker-entrypoint-initdb.d/ - cannot create container for service database 自定义mysql高山映像未从作为卷安装的docker-entrypoint-initdb.d加载init.sql - Custom mysql alpine image not loading init.sql from docker-entrypoint-initdb.d mounted as a volume 当容器从另一个容器中启动时,docker-entrypoint-initdb.d 为空 - docker-entrypoint-initdb.d is empty when container is started from within another container 命令&#39;/ bin / sh -c mysql -u wordpress -pwordpress wordpress &lt;/docker-entrypoint-initdb.d/wordpress.sql&#39;返回非零代码:1 - The command '/bin/sh -c mysql -u wordpress -pwordpress wordpress < /docker-entrypoint-initdb.d/wordpress.sql' returned a non-zero code: 1 docker-entrypoint-initdb 中的 MySQL 脚本不执行 - MySQL scripts in docker-entrypoint-initdb are not executed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM