39- How do you share data?

Data sharing is the volume of the key features of this section, we discuss in detail how between the container and the host, to share data between the container and the container by volume.

Container and host shared data

We have two types of data volume, they can achieve between the container and the host to share data, but way different.

For bind mount is very clear: to be shared directory directly mount to the container. Refer to the previous example httpd, is omitted.

docker managed volume necessary to trouble spots. Since the host is located in the volume directory is generated only when the container starts, it is necessary to copy the data to the shared volume of. Consider the following example:

docker cp Data can be copied between the container and the host, of course, we can also directly by the Linux  copy command to / var / lib / docker / volumes / xxx. cp

Data sharing between the container

The first method is to mount the shared data in the bind, and then mount it into a plurality of containers. Or in httpd as an example, but this scene more complicated, we want to create a web server cluster consisting of three httpd container, they use the same html file, as follows:

1. The $ HOME / htdocs mount three httpd container.

2. Modify the page file volume in view again and confirm that all containers are used in new home page.

Another way to share data between the container using a volume container, discussed in the next section.

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/mkxfs/p/10960650.html