inotifywait with Docker command and variable
I am trying to create a shell script that will check for a new file then cp to a Docker Container. The code I have so far is…
#!/bin/sh source="/var/www/html/" dest="dev_ubuntu:/var/www/html/" inotifywait -m "/var/www/html" -e create -e moved_to | while read file; do sudo docker cp /var/www/html/$file dev_ubuntu:/var/www/html done
But this code gives the following error:
Setting up watches. Watches established. "docker cp" requires exactly 2 argument(s). See 'docker cp --help'. Usage: docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|- docker cp [OPTIONS] SRC_PATH|- CONTAINER:DEST_PATH Copy files/folders between a container and the local filesystem
What am I doing wrong?
One Solution collect form web for “inotifywait with Docker command and variable”
Do you have spaces in your file names? Use double quotes to avoid separating filenames by words:
echo $file sudo docker cp "$file" dev_ubuntu:"$file"
I’ve also echoed the file name to see what is happening.