In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Some containers will automatically generate some data, in order not to let the data disappear with the disappearance of container, to ensure the security of the data. For example: database container, the table of the data table will produce some data, if I delete the container, the data will be lost. In order to ensure that the data is not lost, there is the existence of Volume.
Data Volume structure diagram
The Scheme of persisting data in Docker
Volume based on the local file system. When you can execute Docker create or Docker run again, use the host's directory as the data volume of the container with the-v parameter. This part of the function is the basic volume management of the local file system. Plugin-based Volume that supports third-party storage schemes, such as NAS,aws
Type of Volume
Managed data Volume, automatically created by the docker backend.
Bind the mounted Volume. The specific mount location can be specified by the user.
Data Volume of data persistence
Take the dockerfile file of the official image mysql as an example. Dockerfile specifies the path of the file to be backed up in the current container through volume, but does not specify where to save it to the host.
Volume: map the files in the container to the local host hard disk
Before we use docker run
When you start the mysql image container, the container will generate a volume on the host by default. As to where the location is and what the name is, you can check it with the following command
# View all volumedocker volume ls# delete specified volumedocker volume rm [volume name] # View volume details docker volume inspect [volume name]
At this point, we delete the container and find that the volume data volume is still there and is reserved.
At this point, we will find the name of this data volume name very long and difficult to understand. We can specify the generated volume name docker run-d-v mysql:/var/lib/mysql-- name mysql mysql5.7 with the following command:
-v
: the first parameter is volume name, followed by the directory of files to be backed up (container)
At this point we delete the container and the volume data volume is still there. We use this volume named mysql as the data volume of a new container and overwrite it.
Docker run-d-v mysql:/var/lib/mysql-- name mysql2 mysql5.7
When you enter the mysql2 container, mysql-uroot enters the database and finds that the current database data is the same as the database data in the previously deleted container.
Bind Mounting of data persistence
Unlike the above Data Volume, bind Mounting can only be started by docker run-v, not by using dockerfile files.
When running the container, specify a mapping between a local file directory and a file directory in the container, through which file data can be synchronized. No matter which party has modifications, the other party will synchronize the content.
Docker run-d-v $(pwd): / usr/share/nginx/html-p 80:80-- name nginx nginx
At this time-v: the preceding parameter is the local file path, followed by the docker file directory (container).
It is worth noting that when bind Mounting is used to map data volumes, docker run-v runs for the first time, and if the local folder has no content and the folder in the docker container has content, then the local folder will overwrite the content in the dokcer container, that is, there will be no content in the container.
The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.