(Docker notes): data volume container

Data volume container

  • Data synchronization between containers

  • As shown above, use the parent container to share data with other containers

Case

  • Start two containers docker01 and docker02 through the previously generated image

  • Start docker02
docker run -it --name docker02 --volumes-from docker01 centos:1.0

  • Create files in docker01 data volume

  • View in docker02 data volume volume01

  • Delete docker01, the shared data in docker02 is still there

  • Bidirectional copy of shared volume of container

  • Multiple mysql realize data sharing
docker run -d -p 3310:3306 -v /home/mysql/conf:/etc/mysql/conf.d \
-v /home/mysql/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=123456 --name mysql01 mysql:5.7

docker run -d -p 3310:3306 -e MYSQL_ROOT_PASSWORD=123456 \
--name mysql02 --volumes-from mysql01 mysql:5.7
  • in conclusion:
    • The transfer of configuration information between containers, the life cycle of the data volume container continues until there is no container in use.
    • But once you persist it locally, the local data will not be deleted at this time.

Guess you like

Origin blog.csdn.net/baidu_41388533/article/details/108562453