docker-储存持久化

docker容器不适合存放数据,重要的数据要用外部卷存储,容器可以挂载真实机目录或者共享存储为卷

储存卷映射
docker run -itd -v 真实机目录:容器目录 镜像:标签

可以做一台nfs服务器host01共享/var/webroot目录
docker01服务器把host01的共享目录挂载到/mnt,然后docker01上启动的容器 docker run -itd -v /mnt:/var/www/html 镜像:标签
docker02服务器把host01的共享目录挂载到/mnt,然后docker01上启动的容器 docker run -itd -v /mnt:/var/www 镜像:标签
可以实现两个容器公用一个目录

When nothing seems to help, I go look at a stonecutter hammering away at his rock, perhaps a hundred times without as much as a crack showing in it. Yet at the hundred and first blow it will split in two, and I know it was not that blow that did it, but all that had gone before. -- Jacob Riis
原文地址:https://www.cnblogs.com/xhwy-1234/p/12152131.html