1. Mount the local directory into the container
# docker run-itd-v/data/:/data1/centos bash//-v used to specify mount directory,/data/to local directory,/data1/as directory in container
2. Mount the data volume
Mount the directory, you can specify the name of the container, if not specified randomly defined, such as we did not specify above, he generated a container named Angry_ritchie, the name can be used in Docker PS to see, the right column is
# docker RUN-ITD--volumes-from Angry_ritchie (container's name) CentOS Bash
This creates a new container using the CentOS image and uses the data volumes of the Angry_ritchie container
3. Define Data Volume container
Sometimes we need to share data between multiple containers, similar to NFS in Linux, so we can build a dedicated data volume container, and then other containers will overload the data volume directly:
Creating a Data Volume container
# docker run-itd-v/data/--name fansik CentOS Bash//Note here/data/is the/data directory of the container, not the local/data/directory
Then let the other container mount the data volume
# docker RUN-ITD--volumes-from Fansik--name=zhangsan CentOS Bash
The Fansik container is equivalent to the NFS server, and all the data is stored on the Fansik mirror (so Fansik cannot stop rebooting, etc.)
4. Backup of data volumes
To create backup directory backups:
# mkdir Backup
Create a container using Fansik and mount the backup directory to a container
# docker RUN-ITD--volumes-from fansik-v/backup/:/backup/centos Bash
Enter the container and you'll see a backup directory with the data directory under the root directory.
# Docker exec-it 5A4 Bash
Package The data directory and put it in the backup directory so you can see the data we backed up in the host's backup.
# Tar Cvf/backup/data.tar data
5. Recovery of data volumes
I have removed all the other containers before I recover, just want to use the previous container name
First create a data volume container, build a new container and mount the data volume container, then unpack the tar package
New Data Volume Container:
# docker Run-itd-v/data--name fansik CentOS Bash
Mount the data volume to create a new container, and unpack the package:
# Docker Run--volumes-from fansik-v/backup/:/backup CentOS tar Xvf/backup/data.tar
When this command executes, it exits.
Docker Data Management