I have created a docker volume "hello" and it contains some data .
How can I copy the data to host ?
First :
kerydeMacBook-Pro:~ hu$ docker volume create --name hello
hello
checking :
kerydeMacBook-Pro:~ hu$ docker volume ls
DRIVER VOLUME NAME
local hello
volume "hello" inspect
kerydeMacBook-Pro:~ hu$ docker volume inspect hello
[
{
"Name": "hello",
"Driver": "local",
"Mountpoint": "/mnt/sda1/var/lib/docker/volumes/hello/_data"
}
]
How can i copy the data on the volume "hello" to host?
I tried :
kerydeMacBook-Pro:~ hu$ docker cp hello:/mnt/sda1/var/lib/docker/volumes/hello/_data /Users/hu/Desktop/12
Error response from daemon: no such id: hello
It does not work as expected!
Who can help me ?
Obtain the name or id of the Docker container. Issue the docker cp command and reference the container name or id. The first parameter of the docker copy command is the path to the file inside the container. The second parameter of the docker copy command is the location to save the file on the host.
To export a container, we use the docker export command. The documentation describes export as follows: docker export – Export a container's filesystem as a tar archive. As we can see, this is just a regular old Linux file system — the BusyBox file system created when running our image, to be precise.
To copy data from the volume to the host, use a temporary container that has the volume mounted.
CID=$(docker run -d -v hello:/hello busybox true)
docker cp $CID:/hello ./
To copy a directory from the host to volume
cd local_dir
docker cp . $CID:/hello/
Then clean up the temporary container.
docker rm $CID
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With