【问题标题】:run docker-compose command in crontab在 crontab 中运行 docker-compose 命令
【发布时间】:2021-05-09 08:01:03
【问题描述】:
我有一个docker-compose.yml 和.env 和相同的位置。.env 文件保存docker-compose.yml 文件的环境变量。我想在crontab 中运行docker-compose exec 命令,但我得到一些错误,因为缺少.env 文件。我在docker-compose 命令中使用了--env-file 选项,然后我得到the input device is not a TTY 错误。
我该如何解决这个问题?
【问题讨论】:
标签:
bash
docker-compose
cron
【解决方案1】:
对于docker-compose exec,您必须使用-T 选项。
Options:
-d, --detach Detached mode: Run command in the background.
--privileged Give extended privileges to the process.
-u, --user USER Run the command as this user.
-T Disable pseudo-tty allocation. By default `docker-compose exec`
allocates a TTY.
--index=index index of the container if there are multiple
instances of a service [default: 1]
-e, --env KEY=VAL Set environment variables (can be used multiple times,
not supported in API < 1.25)
-w, --workdir DIR Path to workdir directory for this command.
【解决方案2】:
使用docker-compose exec -T 防止docker-compose 分配tty。
docker-compose默认分配tty。