bash - 如何通过 docker-compose 中的脚本运行 rsync 来输出进度?
问题描述
我正在通过脚本运行 rsync,但没有看到进度条。当我直接运行它时它工作正常,但是当我运行脚本时,我只得到回声。
在我的docker-compose.yml
:
command: /home/node/build-dir/command.sh
tty : true # Show output with syntax highlighting support.
#!/bin/ash
# First check if the directory is empty, as it is when it is mounted for the first time.
if [ -z "$(ls -A /home/node/work-dir/node_modules)" ]
then
echo 'Beginning to copy node_modules folder...'
# Recursively copy all files of build directory to that of the working directory.
rsync -ah --info=progress2 /home/node/build-dir/node_modules /home/node/work-dir/node_modules
echo 'Finished copying node_modules folder...'
else
echo 'The folder "node_modules" already exists; skipping copying.'
fi
# Run npm start command to start development.
exec npm start
我希望它显示进度,然后在完成时停止,完成脚本运行。我希望它就像我直接通过 shell 使用docker exec -it my_app ash
然后运行以下命令运行它一样:
rsync -ah --info=progress2 /home/node/build-dir/node_modules /home/node/work-dir/node_modules
到目前为止,我什么也没得到,因为它的作用与 cp 相同。我得到两个回声“开始复制......”和“完成复制......”就是这样。进展在哪里?
- 我尝试通过带有测试文件的主机上的 shell 运行该命令,并且它有效。
- 我尝试通过带有测试文件的主机上的 shell 运行脚本,并且它有效。
- 我尝试从容器内通过 shell 运行命令并且它有效。
- 我尝试从容器内通过 shell 运行脚本并且它工作。
我唯一的假设是我的文件做错了什么docker-compose.yml
。
解决方案
我docker-compose up...
在应该使用的时候使用docker-compose run...
。
找到我的答案的来源:使用 Docker Compose 的交互式 shell。
推荐阅读
- winapi - winapi - 如何检测鼠标在上下文菜单上的移动
- java - 选定的 Spinner 值在选择时未更改并继续为空
- database - 我正在尝试使用子表单/弹出表单在 MS Access 的子数据表中填充数据
- angular - 如果数据可用,则返回承诺?Firebase-Angular
- azure - 是否可以获得创建天蓝色表存储的代码?
- python - _pickle.UnpicklingError: 找不到 MARK-speaker 识别项目
- java - 如何让 Kafka Consumer 处理 LocalDate 类型?
- javascript - 带有 Angular-Material 的 Chrome 存储 - 不写入,读取的值未定义
- amazon-web-services - 为什么自定义资源未能在 AWS Cloudformation 中按预期时间稳定?
- php - Cron 作业 - 在数据库之间移动数据