Docker data volume container data persistence mode -Docker

To tomcat, for example, if we need to start a docker tomcat container and put our engineering tomcat start

In the absence of data volume, we have adopted ways:

The project will use dockerfile copied to the tomcat webapps directory to create a new image, and then create the container by the new image and start this deployment.

This way is certainly easy to use, but you need to create a new image, if you need to deploy a new project, but also to create a new image. A lot of trouble

Moreover, this approach can cause problems repeated written, it is our project file is essentially written twice on the docker container and the host. Causing performance loss.

Another problem is that most, when we start a project, to upload files to the server's operation, when we actually uploaded to the file docker container, when the container is removed, we uploaded files will be lost a. This has resulted in data not persistent problem.

Then the data volume is how to solve this issue?

First, it shows what use the data volume:

Creating index.html file and write hello Docker!

root@ubuntu_server:/usr/local/docker/tomcat/ROOT# echo hello Docker! >index.html

Start to official data volume way to start tomcat image

docker run -p8082:8080 -d --name tomcat4 -v /usr/local/docker/tomcat/ROOT:/usr/local/tomcat/webapps/ROOT tomcat:jdk8

As can be seen in different commands with the command to start docker conventional container in that the addition of this string -v / usr / local / docker / tomcat / ROOT: / usr / local / tomcat / webapps / ROOT

This is the volume of data usage, through this string of command, we will tomcat webapps / ROOT directory contents of the container, replace / ROOT directory of content created for us on this host.

In fact there is no replacement will just create this folder on the host file data volume, and then tomcat / ROOT directory on the container points to the data volume.

In this way, when we modify the contents of the directory on the container, the contents of the data volume will change, which achieved a persistent data container.



Guess you like

Origin www.cnblogs.com/yinjing/p/12292077.html