简体   繁体   中英

Copy folder content to a named volume in Docker

I have a named volume:

{
    "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"
}

It's mounted to my container:

"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": ""
        }
    ]

I would like to copy the content (including sub folders) from a local folder to the volume. I have tried this:

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

This doesn't return any errors but it's not working. The files are not being copied. I have used this answer as a guide: https://github.com/moby/moby/issues/25245#issuecomment-365980572

I would be very thankful if anyone could point me in the right direction to get this working.

You need to copy to the destination your volume is mounted to. In your case to /var/www/html/wp-content/uploads not example_uploads

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

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