In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
In this article, the editor introduces in detail "what is the method of docker data management", the content is detailed, the steps are clear, and the details are handled properly. I hope that this article "what is the method of docker data management" can help you solve your doubts.
Data management currently provides the following two ways:
(1) data volume data volumes
(2) data volume container data volumes containers
Data volume
Data volume, to put it bluntly, is a special directory, similar to the mount mount operation on directories or files under linux, except that it bypasses the file system. It has the following characteristics:
(1) data volumes can be shared and reused among containers
(2) changes to the data volume will take effect immediately
(3) updates to the data volume will not affect the mirror (mirror read-only)
(4) the volume will always exist until no container is used.
The addition of data volumes can be set by the-v parameter, followed by the directory. Here is an example:
Create a data volume / homedata into the container os123
[root@docker5 home] # docker run-d-ti-- name os123-v / homedata centos [root@docker5 home] # docker exex-ti os123 / bin/bash [root@d1a05a7d5efe /] # lltotal 40 RWKui. 1 root root 18301 Jun 2 13:27 anaconda-post.loglrwxrwxrwx. 1 root root 7 Jun 2 13:25 bin > usr/bindrwxr-xr-x. 5 root root 380 Jun 23 02:42 devdrwxr-xr-x. 48 root root 4096 Jun 23 02:42 etcdrwxr-xr-x. 2 root root 6 Aug 12 2015 homedrwxr-xr-x. 2 root root 6 Jun 23 02:42 homedata.. [root@d1a05a7d5efe /] # cd homedata/ [root@d1a05a7d5efe homedata] # lltotal 0 [root@d1a05a7d5efe homedata] # touch 21yunwei.txt; echo 123 > > 21yunwei.txt [root@d1a05a7d5efe homedata] # cat 21yunwei.txt123
Mount a directory / home/data on the local server to the container os456 directory / homedata
Home/data creates a file 1.txt and content hello world in advance.
[root@docker5 home] # docker run-d-ti-- name os456-v / home/data:/homedata centos [root@docker5 home] # docker exec-ti os456 / bin/bash [root@9347d5ef84ff homedata] # cd / homedata;cat 1.txthello world
Through the above two containers os123 and os456, you have a basic understanding of how to create a data volume and how to mount a local directory to a data volume. Note that if the data volumes in the two containers are mounted separately (that is, the same data volume container is not mounted), the data will not affect each other. If you enter different data volumes in the same directory, such as / homedata, the contents can be different.
Note: when you delete a container, the data volume is not deleted. If you want to delete the container and delete the data volume at the same time, add the-v parameter. For example: docker rm os456-v / homedata
Data volume container
Most of the time, the established container is not single, and requires data sharing, data synchronization and update operations between containers. This requires the establishment of a data volume container.
A data volume container is an ordinary container with a set data volume in it, which is specially provided for mounting other containers. This is done by-volumes-from the data volume container name.
I have a website program that is placed in the local / home/webdata directory of the server. Here, create a data volume container webdata and mount the / home/webdata on my server to the / web directory of the data volume container:
[root@docker5 home] # docker run-d-ti-- name webdata-v / home/webdata:/home/web centos
Enter the container and view the data
[root@docker5 home] # docker exec-ti webdata / bin/bash [root@289598d6e24d /] # cd / home/web/ [root@289598d6e24d web] # lltotal 7872drwxr-xr-x. 3 root root 54 Mar 27 2013 META-INFdrwxr-xr-x. 6 root root 4096 Dec 25 2014 WEB-INFdrwxr-xr-x. 3 root root 63 Mar 27 2013 cssdrwxr-xr-x. 2 root root 8192 Mar 27 2013 flags-rw-r--r--. 1 root root 97 Mar 27 2013 index.jspdrwxr-xr-x. 2 root root 4096 Mar 27 2013 jsdrwxr-xr-x. 2 root root 6 Jun 23 03:43 probe
By setting up the 1.txt and inserting the content here, you can see that the / home/webdata data on the server is synchronized. It can be seen that there is no problem with container and directory mounting.
[root@docker5 home] # docker run-dti-- volumes-from webdata-- name os147 centos [root@docker5 home] # docker run-dti-volumes-from webdata-- name os258 centos
Two containers are created, both of which mount the same data volume container through-volumes-from webdata, and both enter os147 and os258 to view / home/web visible data, so the data sharing synchronization is realized here.
[root@docker5 home] # docker exec-ti os147 / bin/bash [root@b4cfa4c4e11c /] # cd / home/web/ [root@b4cfa4c4e11c web] # lltotal 7876Murray RWKI. 1 root root 11 Jun 23 03:46 1.txtdrwxr-xr-x. 3 root root 54 Mar 27 2013 META-INFdrwxr-xr-x. 6 root root 4096 Dec 25 2014 WEB-INFdrwxr-xr-x. 3 root root 63 Mar 27 2013 cssdrwxr-xr-x. 2 root root 8192 Mar 27 2013 flags-rw-r--r--. 1 root root 97 Mar 27 2013 index.jspdrwxr-xr-x. 2 root root 4096 Mar 27 2013 jsdrwxr-xr-x. 2 root root 6 Jun 23 03:43 probe
Description:
1. You can mount multiple directories from multiple containers using the-volume-from parameter multiple times. Data volumes can also be mounted from other containers that have already been mounted (similar to delivery).
2, emphasize again: if the mounted container is deleted, the data volume will not be deleted automatically. If you want to delete the container and delete the data volume at the same time, add the-v parameter.
Data backup, data recovery and data migration through data volume containers
Backup
Let's create a container dedicated to backing up probe: probebak to back up the data in the data volume container, with the following command
Docker run-dti-- volumes-from webdata-- name probebak-v / home/web_probebak:/backup centos tar zcvf / backup/web_probe.tar.gz / home/web
Command mounts the data volume container webdata to create a dedicated backup container probebak, and mounts the server local directory / home/web_probebak to the / backup directory on the backup container. After the container starts, it executes the tar zcvf / backup/web_proce.tar.gz / home/web operation, completes the / home/web backup on the server, and packages it to / backup/web_proce.tar.gz. That is, it is packaged into / home/web_probebak/web_probe.tar.gz to achieve data backup.
Restore
Create a container os999 that holds the data volume / testdata
[root@docker5 home] # docker run-v / testdata-- name os999 centos / bin/bash
Create another container, mount the data volume just set through-volumes-from os999, and decompress the data:
[root@docker5 home] # docker run-- volumes-from os999-v / home/web_probebak:/backup busybox tar zxvf / backup/web_probe.tar.gzUsage of loopback devices is strongly discouraged for production use. Either use `--storage-opt dm.thinpooldev` or use`-- storage-opt dm.no_warn_on_loop_devices= true` to suppress this warning.home/web/home/web/probe.ziphome/web/probe/home/web/css/home/web/css/classic/home/web/css/classic/datasourcetest.css. This article "what is the method of docker data management" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it. If you want to know more about the articles, you are 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.
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.