在bash文件中运行docker命令并使用crontab运行 [英] Run docker command in bash file and run using crontab
本文介绍了在bash文件中运行docker命令并使用crontab运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#!/bin/bash
docker exec -ti erpnext sh -c "cd /home/frappe/frappe-bench/ &&
/usr/local/bin/bench backup"
echo 'Hello, world.' >foo.txt
上面的代码是我的bash文件. 这里有两个命令
The above code is my bash file. Here have two command
- 创建txt文件
- 执行docker容器
如果我运行此命令
cd /home/arifur/workspace_python/erpdatabasebackup && bash backup_database.sh
在终端上就可以了
但是当我在crontab中运行
But when I run in crontab
* * * * * cd /home/arifur/workspace_python/erpdatabasebackup && bash backup_database.sh
然后只能创建txt文件,但docker容器不起作用.
then only txt file creation is working but docker container is not working.
推荐答案
-ti
请求使用伪tty并以交互模式运行,但cron不会附加到任何TTY.尝试像
The -ti
requests to use a pseudo-tty and run in interactive mode but cron does not attach to any TTY. Try removing -ti
as in
docker exec erpnext sh -c "cd /home/frappe/frappe-bench/ && /usr/local/bin/bench backup"
这篇关于在bash文件中运行docker命令并使用crontab运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文