Docker Community Forums

Share and learn in the Docker community.

How to access docker volume data from host machine?


I have important config files needed for the nms tool inside container directory - /var/lib/enms. Also when the container run other data related to the container save it in the same /var/lib/enms directory. I wanted to take backup of this data in local host machine. so run the below command.

docker run -v /root/nms:/var/lib/enms mohanstack/nms:1.0

Above docker command completely wiped off the container directory /var/lib/enms. so container throws error and quits

But when If I did below steps, the already existing data in container /var/lib/enms not erasing and newly added data are copied to created volume and container works fine.

docker volume create nmsvol

docker run -v nmsvol:/var/lib/enms mohanstack/nms:1.0

But the problem is I dont find a way to access the volume data nmsvol. Is there way that I access the data of the nmsvol from the local system,


Your first attempt used a bind.
Your second attempt used a named volume. Only with named volumes existing data is copied from the container target folder into the volume.

You can configure a named volume that binds a host folder into the container:

docker volume create --driver local -o o=bind -o type=none -o device="/root/nms" nmsvol
1 Like

Here is a simple command to start a temporary Debian container and copy all the data from nmsvol to a tar file in the current directory:

docker container run --rm -v "nmsvol:/source" -v "$(pwd):/backup" -w /source debian tar czf /backup/nmsvol.tar.gz .
1 Like

The question I believe you are asking is: where does the “docker volume create” command place the “nmsvol” volume? I don’t know if that changes with different installs of Docker on different hosts, but I use PhotonOS and there Docker stores volumes in the /var/lib/docker/volumes directory. Maybe take a look there.


This worked, thanks.

1 Like

Thank you very much. After hours of coding and recoding, searching the internet and a stackoverflow question…none of which worked,
your answer fixed it.

I use this handy function to list the content of my volumes:

dvolume() {
local volume volumes_to_list={1:-(docker volume ls --quiet)}
for volume in volumes_to_list; do sudo ls -lRa "(docker volume inspect --format ‘{{ .Mountpoint }}’ “$volume”)"
Notice you can call the function in two ways:

dvolume # for each volume, list its content dvolume # list 's content