数据持久化演变
docker run -d --name n1 -p 81:80 nginx:1.16
docker container exec -it n1 /bin/bash
echo 'test'>index.html
手工交互
docker container cp index.html n1:/usr/share/nginx/html/
docker container cp n1:/usr/share/nginx/html/index.html ./
挂载方式
mkdir /H && echo 'H'>/H/index.html
docker stop n1
docker rm n1
docker run --name n1 -p 81:80 -d -v /H:/usr/share/nginx/html nginx:1.16
一般情况下:日志,数据,数据库做持久化
----------------------------------------------------------------------------------------------------------------------------------------------------
批量持久化
mkdir -p /opt/Volume/{a,b}
touch /opt/Volume/a/a.txt
touch /opt/Volume/b/b.txt
docker run -d --name n0 -v /opt/Volume/a:/opt/a -v /opt/Volume/b:/opt/b nginx:1.16 用来做挂载模板 容器名称为n0
docker run -d -p 8081:80 --volumes-from n0 --name n1 nginx:1.16 使用模板n0 :--volumes-from n0
docker run -d -p 8082:80 --volumes-from n0 --name n2 nginx:1.16
----------------------------------------------------------------------------------------------------------------------------------------------------
[root@test1 ~]# docker exec -it n1 /bin/bash
root@40ccd4412369:/# cd /opt/
root@40ccd4412369:/opt# ls
a b
root@40ccd4412369:/opt# ls a b
a:
a.txt
b:
b.txt
root@40ccd4412369:/opt#
----------------------------------------------------------------------------------------------------------------------------------------------------