Storage volumes
- docker container does not hold any data
- Use an external volume of important data stored (data persistence)
- Container can mount a real local directory or shared storage for the volume
1) mapping host volume
- The real machine directory is mounted to the container provides persistent storage
- Directory does not exist is automatically created, directory exists directly overwrite
docker run -itd -v /mnt/html:/var/www/html myos:httpd
2) use file-sharing services among container to achieve different hosts to share files
[root@nfs ~] yum -y install nfs-utils
[root@nfs ~] mkdir /tmp/webroot
[root@nfs ~] echo 'test html page' > /tmp/webroot/index.html
[root@nfs ~] vim /etc/exports
/tmp/webroot *(rw)
[root@nfs ~] systemctl start nfs
[root@docker1 ~] yum -y install nfs-utils
[root@docker1 ~] mount -t nfs 192.168.1.38:/tmp/webroot /mnt/html
[root@docker1 ~] docker run -itd -v /mnt/html:/var/www/html docker.io/http
[root@docker2 ~] yum -y install nfs-utils
[root@docker2 ~] mount -t nfs 192.168.1.38:/tmp/webroot /mnt/html
[root@docker2 ~] docker run -itd -v /mnt/html:/usr/share/nginx/html docker.io/nginx