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:
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.
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.
Well it pretty much depends on the driver and type. The local driver is able to mount whatever you can mount on the host. Most parameters of the mount command work here as well, but some of them might require a slightly different syntax.
device: hostpath
nmsvol: name of the volume
The declaration of the volume will be still present in /var/lib/docker/volumes/${volume}/opts.json, but the data will be whatever path you picked as device.
You can do that, but you need to be root which makes it a bit more complicated. I would also avoid working in the docker data root directory directly, but again, if you are careful, you can do that.