5.Docker storage volumes

I. Overview

1, Docker underlying storage mechanism

Docker image formed by a plurality of read-only overlay of, when starting container, Docker loads read-only image layer and add a layer on top of the mirror stacks reader.

If you are running in the container modify the existing file that already exists, then the file will be copied from read-only to read and write layer below layer to layer read-write, read-only version of the file is still there but has been read layer copy of the file hidden, namely "copy (COW) write" mechanism. This mechanism in the access and use efficiency is very low.

When writing copy mechanism is: if a file exists at the bottom, is marked for deletion at any level, then the user can not see the top of the file. Users can see not only marked as deleted or marked as deleted in the uppermost layer has its own user creates a file with the same name.

Existing docker container storage mechanisms: Joint stored in the file system, easy access to the host; sharing of data between vessels inconvenience; deleted container data will be lost.

Solution: Volume (Volume), one or more "Contents" on the container, such directories may bypass a directory on the file system and joint host "binding (association)."

2, storage volumes (Volume)

The so-called storage volumes can be thought of as simply find there is a directory on the local file system in which a privileged class name space (host), this directory to establish a binding relationship directly with a directory on the inside of the container file system .

Volume mind is independent of the vessel's life-cycle data persistence, so the default is not deleted when you delete container volume, nor will unreferenced volumes do garbage collection. You can specify the storage volume be deleted when you delete the container.

docker storage volume default is to use local host files disk directory where the container is located. Can mount an NFS file directory on the host, then the container to use this directory.

Second, common operations

1, docker volume of two types

Bind-mounted volumes: specify the directory on the docker bound catalogs and host. After the destruction of the vessel default directory on the host will not be deleted.

[root @ ~ Oracle] RUN # Docker Container --name B1 -v / Data / Volumes / B1: / Data - RM - IT busybox: Latest # If the directory does not exist on the host, docker automatically created 
[root @ Oracle ~] # B1 Docker Container Inspect

docker managed volume: docker container specified directory, the directory on the host automatically created by the docker in a particular directory. After the destruction of the vessel default directory on the host will be deleted (may be related to version).

[root@oracle ~]# docker container run --name b1 -v /data --rm -it busybox:latest
[root@oracle ~]# docker container inspect b1
[root@oracle ~]# docker container inspect -f {{.Mounts}} b1 #过滤出Mounts字段

2, the shared storage volume

  • Two containers while building a relationship with the same host directory, you can share data between the two containers.
  • A copy storage volume container path already exists when starting a new container.
[root@oracle ~]# docker container run --name b1 -v /data/volumes/b1:/data --rm -it busybox:latest
[root@oracle ~]# docker container run --name b2 --volumes-from=b1 --rm -it busybox:latest 
[root@oracle ~]# docker container inspect -f {{.Mounts}} b2

Guess you like

Origin www.cnblogs.com/cmxu/p/11650772.html