<title>Data Management for Docker containers</title> Data management for Docker containers What is a data volume (Volume)?
- A data volume is a specially crafted directory that bypasses the Federated file System (UFS) and provides access to one or more containers
- The purpose of the data volume design is to perpetuate the data, which is completely independent of the container's lifetime, so Docker will not delete its mounted data volumes when the container is deleted, nor will there be a similar garbage collection mechanism to process the data volumes referenced by the container
Features of the data volume (Volume)
- The data volume is initialized when the container starts, and if the image file used by the container contains data at the mount point, the data is copied to the newly initialized data volume
- Data volumes can be shared and reused between containers
- Can modify the contents of the data volume directly
- Changes to the data volume do not affect the update of the image file
- The volume will persist even if the container on which the data volume is mounted has been deleted
Use of data volumes to add data volumes to containers
1.run -v ~/container_data:/data -it ubuntu /bin/bash
~/container_data
: Native file directory
/data
: File directory in container
Add access rights to a data volume
1.~/datavolume:/data:/bin/bash
:ro
: Read-only file permissions
Use Dockerfile to build mirrors that contain data volumes
Dockerfile directive:
VOLUME["/data"]
Data volume container What is a data volume container?
The named container mounts the data volume, and the other container implements the data share by mounting the container, which is called the data volume container.
How to mount a data volume container
1.run--volumes-from [CONTAINER NAME]
Back up and restore data backup methods for data volumes
1.docker run --volumes-from [container$(pwd):/backup ubuntu tar cvf /backup/backup.tar [container data volume]
Data Restore Methods
1.docker run --volumes-from [container$(pwd):/backup ubuntu tar xvf /backup/backup.tar [container data volume]
Data Management for Docker containers