docker data volume (volume)

1. What is a data volume

     In order to understand what a Docker Volume is, first we need to understand how the file system inside Docker works. Docker images are stored in a series of read-only layers. When we start a container, Docker reads the read-only image and adds a read-write layer on top. If a running container modifies an existing file, the file will be copied out of the bottom read-only layer to the top-level read-write layer. The old version of the file in the read-write layer is hidden under this file, but it is not uncorrupted - it still exists under the mirror. When a Docker container is deleted and then the image is restarted, a new container will be started with no changes - those changes will be lost. The combination of this read-only layer and the read-write layer on top is what Docker calls the Union File System.
In order to save (persistent) data and share data between containers, Docker proposes the concept of Volumes. Quite simply, volumes are directories (or files) that are either external default union filesystems or normal directories and files that exist in the host filesystem.

 

2. Why use the data volume volume

 

 Docker's image is composed of a series of read-only layers. When starting a container, Docker loads all the read-only layers of the image and adds a read-write layer on top. This design enables Docker to improve the efficiency of image construction, storage and distribution, saving time and storage space, but there are also the following problems.

   (1) The files in the container have complex forms on the host, and the files in the container cannot be easily accessed on the host.

   (2) Data between multiple containers cannot be shared

    (3) When the container is deleted, the data generated by the container will be lost

    To solve these problems, Docker introduced the volume mechanism. A volume is a specific file or folder that exists in one or more containers. This directory can exist in the host machine independently of the federated file system, and provides convenience for data sharing and persistence.

    (1) The volume is initialized when the container is created, and the files in it can be used when the container is running

    (2) Volume can be shared and reused between different containers

     (3) Operations on the data in the volume will take effect immediately

   (4) Operations on the data in the volume will not affect the image itself

   (5) The life cycle of the volume is independent of the life cycle of the container. Even if the container is deleted, the volume will still exist, and the volume that is not used by any container will not be deleted by Docker

 

http://blog.csdn.net/dream_broken/article/details/52314993

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326232484&siteId=291194637