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:

  • Docker.io init.d script not working on start container
  • certbot.main:Exiting abnormally
  • Install Ambari based on docker on multiple hosts
  • Do I really need docker swarm?
  • incremental `docker image save <images> | xz -zc - >images.tar.xz`
  • Is virtualization still relevant with docker?
  • 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?

  • Mono TLS1.2 issues - btls-cert-sync “command not found”
  • Run shell script inside a container
  • Can't connect to django server running inside docker container (Docker for mac)
  • Docker compose doesn't recognize 'env_file'
  • connect to docker hosted on remote server
  • Running impala sql script from Docker file
  • 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.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.