Docker Series 7: Logical Volume

I. Introduction storage volumes

1. What is the storage volume (volume)

  • Will be a directory and a host of a synchronous container up, it is called Volume, i.e. storage volume.

  • When the data generated in the container, this data will be written directly to a physical disk, to solve the problem of performance

  • Use storage volumes, also implements persistent storage of data

  • By using the storage volumes, it may also be implemented distributed

    image.png

2, the type of storage volume

  • Bind mount volume:

  • Docker managed volume

Bind mount volume

  • This means that when creating the type of container, it is necessary to specify a directory mount point and host vessel simultaneously, so to complete the mount

Docker managed volume

  • This type is created when the container is only necessary to specify the same mount point in the container, no need to specify the host to mount directories can be completed.

  • The host directory is generated automatically by Docker, but randomly generated, default: / var / lib / docker / vfs / dir / xxxx

Case 1: Create a docker managed volume

[root@host1 ~]# docker run --name httpd1 -it --rm -v /data busybox
/ # 
/ # echo "test message">>/data/test.txt
/ #
[root@host1 ~]# docker inspect httpd1
"Mounts": [
            {
                "Type": "volume",
                "Name": "636a1967c63705161f941550edf4b0ced1584bf71087596ad61a49df4cd6ae4c",
                "Source": "/var/lib/docker/volumes/636a1967c63705161f941550edf4b0ced1584bf71087596ad61a49df4cd6ae4c/_data",
                "Destination": "/data",
                "Driver": "local",
                "Mode": "",
                "RW": true,
                "Propagation": ""
            }
        ],
[root@host1 ~]# cd /var/lib/docker/volumes/636a1967c63705161f941550edf4b0ced1584bf71087596ad61a49df4cd6ae4c/_data
[root@host1 _data]# cat test.txt 
test message
[root@host1 _data]#

Case 2: Create a container, use the host / disk directory is mounted to the container

[root@host1 ~]# docker run --name httpd1 -it --rm -v /disk:/data busybox
/ # 
/ # echo "test message">/data/t.txt
/ #
[root@host1 ..]# cat /disk/t.txt 
test message
  • / Disk on the host if not present, will automatically create

We set the same in the storage volume for the container when the container may be provided with a roll and stored storage volume of another container

Case 3: For example, we do a good job in front of the container httpd1, where we do a httpd2 , let 2 and 1 the same storage volume with

[root@host1 ..]# docker run --name httpd2 --rm -it --volumes-from httpd1 busybox
/ # 
/ # Ls / data /
t.txt
/ #

3, for example using the infrastructure of the container

  • First, we can first make a container that does not need to run, but only as an infrastructure to support container

  • Copy the new container volume is in this container, for example, three containers out copying, first is nginx as a reverse proxy, the second is a static apache out request, a third request php php process:

    image.png

  • The infrastructure supporting the container may also be provided in a common name space, so that the above three containers have the same the IP , the hostname, but also based on 127 communicate with a

Case: infrastructure-based container production container

1) create infrastructure container

[root@host1 ~]# docker run --name base1 -it --rm -v /disk:/data busybox

2) create nginx container, copy volume infrastructure, and the use of the name space infrastructure

[root@host1 ..]# docker run --name nginx1 \
> --network container:base1 \
> --volumes-from base1 -it nginx:1.14-alpine

Filter container attribute data

  • docker inspect the result is a list of string in the list format json list

  • If at this time To filter the data, which is format docker inspect -f {xxx} b5 to achieve filtering effect

  • -F {} is a double rear, outside fixed format is {}, {} represents the inner filter from the {}

  • Filter element format -f '{{.path.item}}'

[root@host1 ..]# docker inspect httpd1 -f '{{.Id}}'
24053ef79c61400f0f8a151087bfd7c1e31e004ee9b87b8a2e64f1efd72d2b52

[root@host1 ..]# docker inspect httpd1 -f '{{.State.Status}}'
running



Guess you like

Origin blog.51cto.com/54dev/2460948