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
A record of an online MySQL transaction problem L...
Table of contents 1. Application Lifecycle 2. Pag...
Table of contents Previous words Synchronous and ...
WeChat applet calculator example, for your refere...
On Linux, bash is adopted as the standard, which ...
This article shares the specific code of Element-...
In the Linux system, in addition to various accou...
Table of contents Introduction Architecture Advan...
Table of contents JavaScript Objects 1. Definitio...
Official documentation: https://dev.mysql.com/doc...
In daily work, we sometimes run slow queries to r...
Installation Environment Description •System vers...
mistake The following error occurs when connectin...
Table of contents MySQL inner join, left join, ri...
Recently, the following effects need to be achiev...