How to copy data from docker volume to host?

Docker does not provide an interface to access volumes directly but you can use a container that has the volume mounted. This may need a temporary container to be created:

CID=$(docker run -d -v hello:/hello busybox true)

Copy a directory from volume to host

docker cp $CID:/hello ./

To copy a directory from the host to volume

cd local_dir
docker cp . $CID:/hello/

Then clean up (if using a temporary container).

docker rm $CID

Leave a Comment

tech