简体   繁体   中英

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

I'm running rsync through a script, but I'm not getting the progress bar. It works fine when I run it directly, but when I run the script, I only get the echoes.

In my 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

I want it to show the progress and then stop when it finishes, finishing the script run. I want it to be as if when I run it directly through the shell using docker exec -it my_app ash and then running the following:

rsync -ah --info=progress2 /home/node/build-dir/node_modules /home/node/work-dir/node_modules

So far, I get nothing, as in it acts the same as cp. I get the two echos "Beginning to copy..." and "Finished copying..." and that's it. Where's the progress?

  • I tried to run the command through the shell on my host with test files and it worked.
  • I tried to run the script through the shell on my host with test files and it worked.
  • I tried to run the command through the shell from within the container and it worked.
  • I tried to run the script through the shell from within the container and it worked.

My only assumption is that I've done something wrong with my docker-compose.yml file.

I was using docker-compose up... while I was supposed to use docker-compose run... .

Source for finding my answer: Interactive shell using Docker Compose .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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