I have question regarding volumes and ownership.
As an example I'm using this image: privatebin, but this is the same for any case.
First I'm creating volume:
$ docker volume create privatebin-data
From docker inspect, I can see where data is located:
$ docker inspect privatebin-data
[
{
"CreatedAt": "2018-12-04T21:42:46+01:00",
"Driver": "local",
"Labels": {},
"Mountpoint": "/var/lib/docker/volumes/privatebin-data/_data",
"Name": "privatebin-data",
"Options": {},
"Scope": "local"
}
]
Following instructions from docker hub, I'm starting image:
$ docker run -d --restart="always" --read-only -p 8080:80 -v privatebin-data:/srv/data privatebin/nginx-fpm-alpine:1.1.1
Then I visit http://localhost:8080 and everything is working as expected.
Content of volume now:
$ ls -l /var/lib/docker/volumes/privatebin-data/_data
total 16
drwx------ 3 82 82 4096 Dec 4 21:49 73
-rw-r----- 1 82 82 46 Dec 4 21:49 purge_limiter.php
-rw-r----- 1 82 82 529 Dec 4 21:49 salt.php
-rw-r----- 1 82 82 131 Dec 4 21:49 traffic_limiter.php
I want to backup directory by archiving it:
tar -C /var/lib/docker/volumes/privatebin-data -czf privatebin-data-backup.tar.gz _data
My question is: Can I safely assume that if I restart image, for example on other server, user and group owner will still be 82? Is this proper way of backuping and restoring docker volumes?
To back up a data volume you can run a new container using the volume you want to back up and executing the tar command to produce an archive of the volume content as described in the docker user guide. In your particular case, the data volume is used to store the data for a MySQL server.
If a volume is mounted on top of an existing directory in the container, docker export will export the contents of the underlying directory, not the contents of the volume. Refer to Backup, restore, or migrate data volumes in the user guide for examples on exporting data in a volume.
run two docker containers - one on the source the other on destination, each with one volume mounted - the source volume and destination volume. then run on the other of volumes rsync client that would connect to localhost:rsync , effective connecting via " socat pipe" to the rsync --daemon .
Volumes are stored in a part of the host filesystem which is managed by Docker ( /var/lib/docker/volumes/ on Linux).
The UID/GID come from inside your image, privatebin/nginx-fpm-alpine. So as long as you create users in the same way/order in there, and nothing changes in your base image, then those ID's will be the same regardless of where you run the image.
My preferred way to backup and restore volumes is to use a utility container, just in case the backend of docker changes, or you decide to move your named volume to another location or external data store. The commands to do that look like:
docker run --rm \
-v privatebin-data:/source:ro \
busybox tar -czC /source . >privatebin-data-backup.tar.gz
and
docker run --rm -i \
-v privatebin-data:/target \
busybox tar -xzC /target <privatebin-data-backup.tar.gz
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