What is volume? Volume means capacity in English, and in Docker it means data volume, which is a container used to store data. Why data sharing? There are multiple Tomcats in a cluster. The codes deployed to Tomcats in the cluster are copies of the same code. If the page file changes, it means that the page file in each container must be updated. In a large-scale cluster, such 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 data copy. How can we achieve this in a docker environment? Data Sharing Principles Create a space on the host's hard disk to store shared data. Multiple containers share this directory. Solutions to achieve data sharing When it comes to data sharing, it is easy to think of the mount command in Linux, which mounts a shared directory. [x] Use the parameter [x] Use the parameter Container directly mounts shared directories Resources List Prepare two tomcat containers: Detailed steps Creating shared data Create a shared directory: I am a volume shared directory albk! Create docker run -d --name tomcat8000 -p 8000:8080 -v /usr/local/docker/volumn:/usr/local/tomcat/webapps tomcat docker run -d --name tomcat8001 -p 8001:8080 -v /usr/local/docker/volumn:/usr/local/tomcat/webapps tomcat When starting the container, mount the host's Verify that the container is started normally docke ps Browser access Modify shared files Re-authenticate the browser You can see that our modified content has taken effect in real time, and there is no need to redeploy the tomcat container. However, this will cause the parameters to be very long each time the container is started, which is prone to errors. This is acceptable when the cluster is small, but it is also a lot of work when the scale is large. Let's take a look at another method. Shared container mounting Create a shared container docker create --name webpages -v /usr/local/docker/volumn/pages:/usr/local/tomcat/webapp tomcat /bin/true Mounting a shared container docker run --name tomcat8000 -d -p 8000:8080 --volumes-from webpages tomcat docker run --name tomcat8001 -d -p 8001:8080 --volumes-from webpages tomcat The verification process is the same as above. The actual function of the container webpages is to define a mount point. When modifying the content, you only need to modify the shared directory of the shared container. Summarize If there are few containers, use The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Detailed explanation of how to use join to optimize SQL in MySQL
>>: Vue3.0 handwriting magnifying glass effect
*******************Introduction to HTML language (...
system: CentOS 7 RPM packages: mysql-community-cl...
1. Solution to the problem that the page is blank...
mysql query data from one table and insert it int...
1. Function: xargs can convert the data separated...
I believe that many partners who have just come i...
This article shares a common example of viewing p...
Open any web page: for example, http://www.baidu....
Three tables are connected. Field a of table A co...
When you see a class, what information do you wan...
It is recommended that you do not set the width, h...
transform and translate Transform refers to trans...
Adding the right VS Code extension to Visual Stud...
1. IT Mill Toolkit IT Mill Toolkit is an open sou...
Table of contents Preface Rendering Example Code ...