Docker Data Management (Volumes)

Docker data generated in the container layer can be written, if a new image is not generated by the docker commit, so that the data saved to become part of a mirror, and then when the container removed, naturally no data.

Docker data Mount provides three ways:

Here the main record Volumes way, that is, Docker area in the figure, Docker is the recommended way.

 

Volume is designed to persistent data, completely independent of the life cycle of the container, so Docker does not delete its data volume mounted in the container removed.

Features:

  • Data volume may be reused or shared data between the vessel
  • Volume change can take effect directly
  • Data on the volume changes are not included in the update mirrored
  • The life cycle of the data volume continues to use it until the container is not

 

First, data volume

# Mount directory similar 
docker run -it -v / host directory: / directory within the container centos / bin / bash

The host can see here the / tmp directory mount into the container / home directory of

You can also use the command to view the data volume is mounted successfully.

docker inspect containers ID

 

About data synchronization between the host and the container

Whether the vessel is running or stopped, the changes made to mount the directory of the host, will start after the container is mapped to the corresponding directory container.

Similarly, in the container, to mount the directory operation is mapped to host the corresponding directory.

 

Mount directory permissions

https://docs.docker.com/engine/reference/run/#volume-shared-filesystems

docker run -it -v / host directory: / container directory: ro centos / bin / bash

 

Second, the data volume of the container

Naming container mount data volume, data sharing other container by mounting the container (parent container), the container mount data volume, the data volume is called a container.

Shared transfer between containers: - volumes-from

docker run --name="cent0" -it -v /tmp:/home1 centos /bin/bash
docker run --name="cent1" -it -v /tmp:/home2 --volumes-from cent0 centos /bin/bash
docker run --name="cent2" -it -v /tmp:/home3 --volumes-from cent0 centos /bin/bash

Create three containers

  • The first container mount / tmp: / home, back child container mounted directory does not affect the parent container
  • A second container on the first container, and because the loading / tmp: / home2, it can be seen that two directories: / home1, / home2
  • A third container based on the container, and because the loading / tmp: / home3, it can be seen that two directories: / home1, / home3, regardless of the second container

Deleted parent containers look at the sub-directory is mounted container case

To mount the directory can be deleted without affecting the parent container child container.

Conclusion: The transfer of information between the container configuration, the data volume of the life cycle continues until no container to use it so far.

 


https://docs.docker.com/storage/volumes/

https://docs.docker.com/engine/reference/commandline/run/

Guess you like

Origin www.cnblogs.com/jhxxb/p/11426293.html