docker series five volumes of data (volumn)

docker data volume (Volumn)

A. Why do we need a data volume

  docker image is superimposed by a plurality of file systems (read-only layer) formed, when we start a container when the server loads the docker mirror layer read-only, read-write and create a layer at the top level. When running the container modify existing files, the file will be copied from the read-only to read-write layer layer, in fact, did not affect the image itself, it is still present in the image. When we removed the container, the container runtime data will be lost, when we re-run by mirroring a container, the container will return to the original state. So the question is, how do we save the data running us? There are two solutions to this problem: a us and we will periodically generate an image of the container by way commit; B is achieved by the data volume... Obviously we can not stop commit to generate a mirror, some people may say you mean by this is achieved by chanting data volumes, but I do not know what is the volume of data, how do you know it easy to use? So then we started to introduce data volumes.

II. What is the data volume

  Data volume inside the container is directly mapped to the directory data directory on the host, regardless of modification of data in the host or the other party in the container are visible.

III. Use of the data volume

3.1 command

  We still use the earlier chapters by centos mirror to explain, in fact, also a command, our job is to explain around the command: Docker RUN -it -v / dataVolumn: / containerDataVolumn centos

                                                

                                                

  As for the other commands the author here does not make too much explanation, just explain -v / dataVolumn: / containerDataVolumn  the meaning of this command, -v is to bind the container directory is mounted to a directory on the host machine, / dataVolumn: / containerDataVolumn path before the colon refers to the directory name is automatically created on the host (we do not have to manually create) the path after the colon refers to the directory name is automatically created in the container.

 3.2 Test data volume

  As we mentioned earlier "on the container or in a host of changes to the data in the other party are visible," then we come back to this section to test the problem.

  A. We created a container under / containerDataVolumn container.txt a directory file and write the contents of the command: echo "the Hello world"> container.txt

                                                

  In the host / dataVolumn view the directory will have container.txt file and view the contents, as shown below:

                                                

  B. Under the new host's / dataVolumn directory host.txt file and write the contents of the command is: echo "is available for purchase"> host.txt

                                               

  In / containerDataVolumn see host.txt directory file container, and view the contents, as shown below:    

                                                    

  B. deleted container to see the host / dataVolumn directory, the file is not lost

                                              

 

 

Guess you like

Origin www.cnblogs.com/miller-zou/p/11104198.html