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

What is the use of container data volume volume in docker

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

Editor to share with you what is the use of the container data volume volume in docker, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Docker container data volume volume

If the data is all in the container, the data will be lost when we delete the container, so we want the data to be persisted.

For example, the MySQL container, we hope that the data can be stored locally, and when the MySQL container is deleted, the data will not be lost.

There can be a technology for data sharing between containers, and the data generated in the Docker container is synchronized locally, which is called volume technology. That is, data mount technology, mount the directory in our container to Linux.

After mounting, the operations we do in the container will be synchronized to the Linux host.

Use data volume method 1: directly use the command to mount-vdocker run-it-v host directory: container directory # test [root@sumarua home] # docker run-it-v / home/ceshi:/home centos / bin/bash# after startup, we can view it through docker inspect container id]

Example

Data persistence of MySQL

[root@sumarua home] # docker run-d-p 3310 MYSQL_ROOT_PASSWORD=666666 3306-v / home/mysql/conf:/etc/mysql/conf.d-v / home/mysql/data:/var/lib/mysql-e MYSQL_ROOT_PASSWORD=666666-- name mysql mysql5.7

Named mount and anonymous mount

# Anonymous mount-the path in the v container docker run-d-p-- name nginx01-v / etc/nginx nginx# to view all volume docker volume ls

# Mount with a name # View docker volume ls through-v volume name: docker run-d-p-- name nginx02-v juming-nginx:/etc/nginx nginx# in the container

We can check the exact location where the volume is mounted.

Docker volume inspect [volume name]

All volumes in the docker container are in / var/lib/docker/volumes/xxxx/_data if no directory is specified.

We can easily find the volume by mounting it by name.

How to determine whether to mount it anonymously or anonymously or specify a path?

-v path in container # Anonymous mount-v volume name: path in container # named mount-v / host path: path in container # specify path to mount

Expand:

# through-v container path: ro rw changes read and write permissions ro readonly # read-only rw readwrite # read-write # default read-write # once the container permission is set, the container has a limit on what we mount. # ro this path can only be operated through the host, but cannot be operated inside the container. Method 2: Dockerfile

Dockerfile is the build file and command script that is used to build the docker image.

Through this script, you can generate an image, the image is layer by layer, the script is a command, and each command is a layer.

# create a dockerfile file with a random name. It is recommended that the content instruction (uppercase) parameter FROM centosVOLUME ["volume01", "volume02"] CMD echo "- end----" CMD / bin/bash# in the Dockerfile# file is the mirrored data volume container.

-- volumes-from

# usage [root@sumarua] # docker run-it-- name docker02-- volumes-from docker01 sumarua/centos

Realize data synchronization and data sharing between containers

The data volume container deletes the file without affecting the data access of other containers mounted on this container. Is a concept of copy, backup copy mechanism.

With the transfer of configuration information between containers, the life cycle of the data volume container continues until no container is used.

But once persisted to the local, the local data will not be deleted.

The above is all the content of the article "what is the use of Container data Volume volume in docker". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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

Development

Wechat

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

12
Report