Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Docker Series 7: logical Volume

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

I. introduction to storage volumes

What is a storage volume (volume)

Synchronize the directory of a container with the directory of a host, which is called volume, that is, the storage volume.

When data is generated in the container, the data is written directly to the physical disk, solving the performance problem

Using storage volumes, the persistent storage of data is also realized.

By using storage volumes, you can also achieve distribution

2. Type of storage volume

Bind mount volume:

Docker managed volume

Bind mount volume

This type means that when creating a container, you need to specify both the mount point in the container and a directory of the host to complete the mount.

Docker managed volume

When creating a container, you only need to specify the mount point in the container, and you do not need to specify a directory in the host to complete the mount.

Directories in the host are generated automatically and randomly by docker. Default: / var/lib/docker/vfs/dir/xxxx

Case 1: create a volume managed by docker

[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 and mount it to the container using the / disk directory of the host

[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

If the / disk on the host does not exist, it will be created automatically

When we set the storage volume used by the container, we can also set that the storage volume used by the container is the same as that of another container.

Case 3: for example, we finished the container httpd1 before, and here we make another httpd2, so that 2 and 1 use the same storage volume.

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

3. Examples of using infrastructure containers

First of all, we can make a container, this container does not need to run, but only as an infrastructure support container

The volume of the newly created container is replicated in this container. For example, three containers are copied. The first is nginx as the reverse proxy, the second is apache static request, and the third is php processing php request:

This infrastructure supports containers and can also provide a common namespace so that the above three containers have the same IP, hostname, and can communicate based on 127s.

Case: making containers based on infrastructure containers

1) create the infrastructure container first

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

2) create a nginx container, copy the volumes of the infrastructure, and use the infrastructure to build the namespace

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

Filter container attribute data

The result of docker inspect is a list, which is a string in json format

If you want to filter the data at this time, the format is docker inspect-f {xxx} b5 to achieve the filtering effect.

-f is followed by double {}, the outer {} is in a fixed format, and the inner {} indicates filtering from {}.

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

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report