In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how Docker realizes data sharing among Volumn containers. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
What is volume?
Volume means capacity in English and data volume in docker. It is a container used to store data.
Why should data be shared?
There are multiple tomcat in the cluster, and the code deployed in the tomcat in the cluster is a copy of the same code. If the page file changes, it means that the page file in each container has to be updated. In a large-scale cluster, this workload will be infinitely magnified. At this time, data sharing is needed to solve this problem. The so-called data sharing refers to multiple containers sharing a copy of data. How should we achieve this in the docker environment?
Principle of data sharing
Open up a space on the host's hard disk to store shared data, and multiple containers share this directory
The solution to realize data sharing
When it comes to data sharing, it's easy to think of the mount command in linux by mounting a shared directory.
[X] use the parameter-v host directory: / container content directory to put the shared files in a file of the host, and then share this directory before multiple containers to achieve data sharing, which requires at startup
[X] use the parameter-v host directory: / container content directory sharing container mount the host shared directory, and then mount the shared container to achieve data sharing
The container mounts the shared directory directly
Resource list
Prepare 2 tomcat containers:
Tomcat8000 tomcat8001
Detailed steps
Create shared data
Create a shared directory: mkdir-p / usr/local/docker/volumn/pages/
Add a shared file to the shared directory: index.html, with the following contents
I am a volumn shared directory albk!
Create tomcat8000 and tomcat8001
Docker run-d-- name tomcat8000-p 8000 usr/local/docker/volumn:/usr/local/tomcat/webapps tomcat 8080-v / usr/local/docker/volumn:/usr/local/tomcat/webapps tomcatdocker run-d-- name tomcat8001-p 8001usr/local/docker/volumn:/usr/local/tomcat/webapps tomcatdocker run-d-- when starting the container, mount the host's / usr/local/docker/volumn directory to the / usr/local/tomcat/webapps directory of the tomcat container, so that the data can be shared.
Verify that the container starts properly
Docke ps
Docker exec-it a05a987b6da0 / bin/bash
Check whether the mount is successful under the webapps directory.
Browser access
Http:// host ip:8000/pages/index.html
Http:// host ip:8001/pages/index.html
Modify a shared file
Echo I am a volumn shared directory albk! has been modified > index.html
The browser verifies again.
You can see that our modified content has taken effect in real time, and there is no need to redeploy the tomcat container. But every time the container is started, the parameters will be very long, and it is easy to make mistakes. This can be done when the cluster is small, but when the scale is large, this is also a lot of work. Let's take a look at another method.
Mount a shared container to create a shared container webpages. Use the above method to mount the shared directory using-v
Docker create-- name webpages-v / usr/local/docker/volumn/pages:/usr/local/tomcat/webapp tomcat/ bin/true
Mount a shared container
Docker run-- name tomcat8000-d-p 8000volumes-from webpages tomcat docker run-- name tomcat8001-d-p 8001volumes-from webpages tomcat docker run-- volumes-from webpages tomcat verification process is the same as above. The actual function of container webpages is to define a mount point. When you modify the content, you only need to modify the shared directory of the shared container to share the article on "how Docker implements data sharing among Volumn containers". Hope that the above content can be helpful to you, so that you can learn more knowledge, if you think the article is good, please share it for more people to see.
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.