Docker Volume use
A data volume is a specially specified directory that leverages the container's UFS file system to provide some stable features or data sharing for the container. A data volume can be shared among multiple containers.
To create a data volume, you can create a data volume with the-v argument just after the Docker Run command, and of course you could create multiple data volumes with multiple-v arguments, and when you create a container with a data volume, You can mount the data volume by--volumes-froms parameters in other containers, regardless of whether the container is running or not. You can also add one or more data volumes by volume instructions in Dockerfile.
If you have some data that you want to share between multiple containers, or if you want to use that data in some temporary containers, the best scenario is that you create a data volume container and then mount the data from that temporary container. For example, the following actions are:
#启动一个Volume_Container容器, contains two data volumes
Docker run-v/var/volume1-v/var/volume2-name volume_container ubuntu14.04 Linux _command
#创建App_Container容器, mount the data volume in the Volume_container container
Docker run-t-i-rm-volumes-from Volume_container- Name App_container ubuntu14.04 linux_command
#或者再创建一个容器, mount the data volume from Volume_container mounted in App_container
Docker run -t-i-rm-volumes-from app_container-name Lastapp_container ubuntu14.04 Linux_command
1 Create a data volume container within a terminal and write a test file within the data volume directory
2 Open a container, mount the data volume of the previous data volume container, and view the test file
Even if you delete the first Data volume container or the middle tier data volume container that you just started, the data volume will not be deleted as long as there are other containers using the data volume.
You can also mount the directory of a local host as a data volume on the container, also after Docker run with the-v argument, but the-V is no longer a separate directory, he is in [Host-dir]:[container-dir]:[rw|ro] format, Host-dir is an absolute path address, if Host-dir does not exist, Docker creates a new data volume, if Host-dir exists, but points to a non-existent directory, Docker also creates the directory and then uses that directory to do the data source. For example:
Docker run-i-t-v/tmp:/mnt Ubuntu/14.04:14.04/bin/bash
You cannot use commands such as Docker Export, save, CP, etc. to back up the contents of a data volume, because the data volume exists outside the mirror, but there is always workaround, as follows:
Docker RUN-RM--volumes-from data-v $ (PWD):/backup busybox tar cvf/backup/backup.tar/data
Create a new container, mount the data volume container, mount a local directory, and then back up the remote Data volume container's data volume through the backup command to the mapped local directory.
Thank you for reading, I hope to help you, thank you for your support for this site!