繁体   English   中英

如何通过docker-compose中的脚本运行rsync来输出rsync的进度?

[英]How to output progress of rsync by running it through a script in docker-compose?

我正在通过脚本运行 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

我希望它显示进度,然后在完成时停止,完成脚本运行。 我希望它就像我使用docker exec -it my_app ash直接通过 shell 运行它,然后运行以下命令一样:

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...

寻找答案的来源: Interactive shell using Docker Compose

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM