首页 > 解决方案 > 如何通过 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 相同。我得到两个回声“开始复制......”和“完成复制......”就是这样。进展在哪里?

我唯一的假设是我的文件做错了什么docker-compose.yml

标签: bashdocker

解决方案


docker-compose up...在应该使用的时候使用docker-compose run...

找到我的答案的来源:使用 Docker Compose 的交互式 shell


推荐阅读