1

我正在尝试创建一个 shell 脚本,它将检查一个新文件,然后 cp 到一个 Docker 容器。我到目前为止的代码是......

#!/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

但是这段代码给出了以下错误:

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

我究竟做错了什么?

4

1 回答 1

0

你的文件名中有空格吗?使用双引号来避免用单词分隔文件名:

echo $file
sudo docker cp "$file" dev_ubuntu:"$file"

我还回显了文件名以查看发生了什么。

于 2017-06-07T16:05:58.483 回答