wordpress 将文件夹内容拷贝到Docker中的命名卷

pokxtpni  于 2022-12-11  发布在  WordPress
关注(0)|答案(2)|浏览(126)

我有一卷名为:

{
    "CreatedAt": "2019-11-18T07:36:02Z",
    "Driver": "local",
    "Labels": null,
    "Mountpoint": "/var/lib/docker/volumes/example_uploads/_data",
    "Name": "example_uploads",
    "Options": null,
    "Scope": "local"
}

它安装在我的容器上:

"Mounts": [
        {
            "Type": "volume",
            "Name": "example_uploads",
            "Source": "/var/lib/docker/volumes/example_uploads/_data",
            "Destination": "/var/www/html/wp-content/uploads",
            "Driver": "local",
            "Mode": "rw",
            "RW": true,
            "Propagation": ""
        }
    ]

我想将内容(包括子文件夹)从本地文件夹复制到卷。我已尝试过以下操作:

docker cp folder-with-sub-folders container_name:/example_uploads

这不会返回任何错误,但它不工作。文件没有被复制。我已经使用以下答案作为指导:https://github.com/moby/moby/issues/25245#issuecomment-365980572
如果有人能给我指出正确的方向,让这件事顺利进行,我将非常感谢。

qlzsbp2j

qlzsbp2j1#

您需要复制到您的宗卷装载到的目标。在您的情况下,复制到/var/www/html/wp-content/uploads而不是example_uploads

docker cp folder-with-sub-folders container_name:/var/www/html/wp-content/uploads
cu6pst1q

cu6pst1q2#

OP中提到的issue 25245现在(2022年12月)包括this gist中详述的可能脚本,Apparatus_Zero

# CP2DockerVol.sh
# Syntax: . ./CP2DockerVol.sh Volume_Name src dst

# check if docker is running
docker 1> /dev/null
# success?
if [ $? -eq 0 ]; then
        # folder/file exist?
        if test -f "$2"; then
                docker container create --name dummy -v $1:/root tianon/true
                docker cp "$2" dummy:"/root/$3"
                docker rm dummy
                echo "Copied $2 to $3 in Volume $1"
        else
                echo "$2 does not exist!"
        fi
else
        echo "Docker is not running!"
fi

但它也提到dorintt的解决方案更适合一般使用。(在这种情况下,用tianon/true替换hello-world也会稍微快一点)
第一次
将主机目录“myvolume_dir“的所有内容复制到卷“myvolume_copy“中,如果该卷尚不存在,则创建该卷)

相关问题