What is Docker Data Volume ?
A data which stored under container is temporary and its get deleted if we reboot the container. To overcome with this challenge we must use data volume.
Data volumes are directories structure that store the data outside Docker container.
One of important advantage of data volume is that this data can be shared among containers.
By default Data volumes are store under /var/lib/docker/volumes/
This can be listed using docker volume ls
[root@siddhesh ~]# docker volume ls
DRIVER VOLUME NAME
local 88699279ba65e23f209cf1a8eea5fd6ed4a64895e508930ec23e1e76c2594b3d
local f69a24b136b3e66df6213b5cb155823e3bc51f7be7ff04556b7b00d468c33c33
[root@siddhesh ~]#
To take the backup of container data volume run following :
[root@siddhesh ~]# docker run --rm --volumes-from centos-test -v $(pwd):/home/siddhesh/ centos tar cvf /home/siddhesh/backup_nginx.tar /var/lib/docker/volumes/f69a24b136b3e66df6213b5cb155823e3bc51f7be7ff04556b7b00d468c33c33/
[root@siddhesh ~]#
Here :
centos-test : Name of the container
$(pwd):/home/siddhesh/ : Backup folder path
backup_nginx.tar : Name of the backup file
To know the data directory of docker container you can run "docker inspect centos-test"
and search for "Mounts" under you can see "Destination" parameter.
Create and manage volumes :
Create a volume :
[root@siddhesh ~]# docker volume create sid-vol
sid-vol
[root@siddhesh ~]#
List Volumes :
[root@siddhesh ~]# docker volume ls
DRIVER VOLUME NAME
local 88699279ba65e23f209cf1a8eea5fd6ed4a64895e508930ec23e1e76c2594b3d
local f69a24b136b3e66df6213b5cb155823e3bc51f7be7ff04556b7b00d468c33c33
local sid-vol
[root@siddhesh ~]#
Inspect Volume :
[root@siddhesh ~]# docker volume inspect sid-vol
[
{
"Driver": "local",
"Labels": {},
"Mountpoint": "/var/lib/docker/volumes/sid-vol/_data",
"Name": "sid-vol",
"Options": {},
"Scope": "local"
}
]
[root@siddhesh ~]#
Remove a Volume :
[root@siddhesh ~]# docker volume rm sid-vol
sid-vol
[root@siddhesh ~]#
In next tutorial we'll see how to attach data volume to the Docker Container.
Comments