Docker快速入门基础教程(3)

7、docker数据存储
[root@docker ~]# docker run -d --name nginx-volume-test1 -v /data daocloud.io/library/nginx
88b24d79a4f3b021325592ceac20e86291166d675b213d60db017548c4d9d960
 
[root@docker ~]# sh docker_in.sh nginx-volume-test1
root@88b24d79a4f3:/# cd /data/
root@88b24d79a4f3:/data# ls
root@88b24d79a4f3:/data# touch hehe
root@88b24d79a4f3:/data# ls -l     
total 0
-rw-r--r-- 1 root root 0 Nov 24 06:30 hehe
 
[root@docker ~]# cd /var/lib/docker/
[root@docker docker]# ll
total 32
drwx------ 6 root root 4096 Nov 24 14:28 containers
drwx------ 5 root root 4096 Nov 24 02:05 devicemapper
drwx------ 3 root root 4096 Nov 24 01:20 image
drwxr-x--- 3 root root 4096 Nov 24 01:20 network
drwx------ 2 root root 4096 Nov 24 01:20 swarm
drwx------ 2 root root 4096 Nov 24 10:09 tmp
drwx------ 2 root root 4096 Nov 24 01:20 trust
drwx------ 3 root root 4096 Nov 24 14:28 volumes
[root@docker docker]# cd volumes/
[root@docker volumes]# ls
4c60775f938a840e5484aee9088bc612977c25a01f5bd164690d94c962e66e60  metadata.db
[root@docker volumes]# cd 4c60775f938a840e5484aee9088bc612977c25a01f5bd164690d94c962e66e60/
[root@docker 4c60775f938a840e5484aee9088bc612977c25a01f5bd164690d94c962e66e60]# ls
_data
[root@docker 4c60775f938a840e5484aee9088bc612977c25a01f5bd164690d94c962e66e60]# cd _data/    容器内的文件实际在物理机上面的的保存目录
[root@docker _data]# ls
hehe
 
[root@docker ~]# docker run -d --name nginx-volume-test2 -v /data/mysql:/mysql daocloud.io/library/nginx   
f7278ce9bd88c26a0c5aaefcb2b39f1f9df0066bc94edb7a530213815e166f5e
 
#-v /data/mysql:/mysql  表示把物理机的/data/mysql目录挂载到容器内的/mysql目录下面 
 
[root@docker ~]# docker run -d --name nginx-volumes -v /data/mysql:/mysql daocloud.io/library/nginx
28c616e44352fc4eafeb2f87dbbb7b6eb9df447235afe027034efa96df1c5071
 
[root@docker ~]# 
[root@docker ~]# docker run -d --name web-node1 --volumes-from nginx-volumes daocloud.io/library/nginx
0f022ce56e8b800cb1a4ac76bb8a326d42e198093146e8661ad3ac8925ad317d
[root@docker ~]# 
[root@docker ~]# docker run -d --name web-node2 --volumes-from nginx-volumes daocloud.io/library/nginx
03d5e88c15f6604eeee2b8af500b8f356ba69adc34710f3c19b813530f19dc3d

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/380e6b8407f5b72765b2288e74c3cde6.html