Features volume data volume docker

Two ways to mirror
Commit mirrored based on an existing vessel
dockerfile image based mirroring

Container underlying technology:
1.cgroup
enables use of the resource quotas, CPU, memory, and disk
 [the root zxw99 @ ~] -d -m RUN # 64M -C Docker the httpd 512: V1
[zxw99 the root @ ~] # CAT / SYS /fs/cgroup/cpu/docker/981a911ba02f5f4b8fb06052271de813521a94012f05922f5ee09ee2636d8626/cpu.shares
512


2, namespace
resources to achieve isolation
PID, UTS, USER, NETWORK, MOUNT, IPC data volumes feature volume data volume is a special directory for one or more of the containers, which allows a directory container, and the host machine of a file or directory binding. Data volumes are designed to persistent data for the data volume you can understand which shared NFS mount points out in, refer to the host shared directory. Mainly has the following functions and features • persistent storage of data in the container resource sharing among • container • container migration (distributed) • the data volume changes will take effect immediately • updates to the data volume will not affect mirrored • Data the default volume will always exist, even if the container is deleted (Note docker self-management will be removed, be sure to make a backup of the data volumes before deleting containers) for data volume in three ways 1. bind to a specific directory of the machine 2.docker from a directory management, docker randomly bound host 3. based on an existing container 1. the binding machine according to the present specific directory Volume Mount the bind [ken1 the root @ ~] RUN # Docker -v / ken1: / var / WWW / the httpd -d -P HTML -v specify data volume / ken1: / var / WWW / HTML   # / ken1 is a directory of the host,
 
 
 

 









 
 
 
 





 





/ var / www / html is a directory within the container, if the container within the directory does not exist, shi is automatically created! Advantages: 1. Easy to manage 2. You can implement data persistence 3. If the host dang, container or inaccessible, you can use NFS sharing, multiple host load balancing. 2.docker self-managed docker manaagerment volume of this bind and mount volume difference is that users can not manage to go to a local directory. docker will bind himself a directory of the host [root @ ken1 ken1] # docker run -d -v / usr / local / apache2 / htdocs -d -P httpd can be viewed through the following command [root @ ken1 ken1] # docker container inspect 1365d65ead56 Note: 1. when a container is removed, the default does not delete data volumes in the docker managerment volume, incidentally, if you want to delete related data volumes when a container is removed, you need to add the option - v 2. If no -v legacy data will be deleted when the volume of the container, so that the volume of data is called an orphan volumes that managed volume per person if the processing volume of orphans? Solution: Step 1: Check the volume root @ zxw99 _data] # LS / var / lib / Docker / Volumes / 034d0d7b346db801f7f0c92c3bb879acebc28d0e17ba6e6eb91d08802a03d152
 




 



 


 



 





0fc92d717a2bc87384b52c8e3f6ebb4e842be857106410364a4c7be793653509
3aab6aa51cd795b932769a2479104b02585d79da87b7f554d96c45b809e8a5f1
950d114e4f29feaeeb5560f2666e7ce4e03794e812cfdd11ac680dbb63f9286f
A4a83390a954fe8c79bba7a0de157690c47900a354229e3f513bebc99cd7b461
F4f82f58cb91d555d17f230a4bdc52c61ca0b6910538c3ddf1870ccc62bd6346

[root@ken1 ken1]# docker volume ls
DRIVER VOLUME NAME
local 986d19ec31801a630dc5209724560b074b025eacdb7cdf4fbbe3d5e6cc7f0771
local d846455965a7bc208478bf7f6cf2f178263fe455c573504572d4a87f299800a1
local f0d96791e2a60a6edf9b6550625bf568520988ffbaffcfa6353e924b4530dc1c
local fa7bcf028a50a168d8b531eaff2dc74e6207421a5b3347430909d75eb4ad76a4
 
第二步:删除相应的孤儿卷
[root@ken1 ken1]# for i in `docker volume ls | grep -v "DRIVER" | awk '{print $2}'`; do docker volume rm $i ;done
 
在删除容器的时候加上-v
[root@ken1 ken1]# docker container rm -f -v a5e91fa77abe1a5
 
注意:
如果使用-v, 相应的数据卷也会被删掉,如果是在生产环境当中,应当做好数据备份工作!
 
 
3.基于一个容器
[root@ken1 ken1]# docker run -d --volumes-from 1e9a4c3b0bc30295d httpd
–volumes-from是基于一个现有的容器进行数据共享,这个参数后面应当跟上相应的容器ID或者容器名
 
数据卷的生命周期管理
 
1.备份
2.迁移
3.恢复
4.销毁
 
1.备份
备份只需要备份相应的数据卷即可,例如:
[root@ken1 ken1]# docker run -d -v /ken:/var/www/html httpd
再上面的额例子中我们只需要做好/ken这个目录下的文件备份即可!
 
2.恢复
只需要重启一个容器,并且绑定ken下面备份的数据即可
 
3.迁移
把ken下面备份好的数据,发送到相应的节点即可,并使用bind mount volume方式运行容器即可
 
4.销毁
情况一:bind mount volumes
这种情况是绑定宿主机的一个目录,如果想要删除数据,只需要删掉宿主机的目录即可
 
情况二:docker managerment volume
需要在删除容器的时候加上选择-v
 
情况三:基于一个容器
 
分为两种情况:
1,如果是docker自管理,删除容器时使用-v
2.宿主机特定目录,需要删除宿主机上的特定目录
 
 
 
验证:数据卷被其他容器使用是否能够删掉
第一步:创建一个新的容器
[root@ken1 ken1]# docker run -d -v /data httpd
 
第二步:查看数据卷
[root@ken1 ken1]# docker inspect 3b1ce4b5f96150e866f322a600f93cd
...
/var/lib/docker/volumes/b0cfa7ae0abe933392c3e649f3d0bec0185c8357c9673ebc0322920cdab8235e/_data
 
第三步:基于现有容器在创建一个容器并绑定数据卷
[root@ken1 ken1]# docker run -d --volumes-from 3b1ce4b5f96150e866 httpd
 
第四步;查看第二个容器的数据卷
发现数据卷和第一个容器使用的数据卷是一致,说明两个容器现在共用一个数据卷
"Name": "b0cfa7ae0abe933392c3e649f3d0bec0185c8357c9673ebc0322920cdab8235e",
 
 
第五步:查看数据卷
[root@ken1 ken1]# docker volume ls
DRIVER VOLUME NAME
local b0cfa7ae0abe933392c3e649f3d0bec0185c8357c9673ebc0322920cdab8235e
 
第六步:删除第一个容器并加上-v选择
[root@ken1 ken1]# docker rm -f -v 3b1ce4b5f961
3b1ce4b5f961
[root@ken1 ken1]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
70df334b3f25 httpd "httpd-foreground" 2 minutes ago Up 2 minutes 80/tcp wonderful_shamir
39d5f620493b httpd "httpd-foreground" 9 minutes ago Up 9 minutes 80/tcp goofy_herschel
c42a2a22c533 httpd "httpd-foreground" 12 minutes ago Up 12 minutes 80/tcp admiring_wilbur
1e9a4c3b0bc3 httpd "httpd-foreground" 24 minutes ago Up 23 minutes 80/tcp blissful_haslett
a6304e984f93 httpd "httpd-foreground" About an hour ago Up About an hour 0.0.0.0:32778->80/tcp brave_varahamihira
[root@ken1 ken1]# docker volumes ls
docker: 'volumes' is not a docker command.
See 'docker --help'
[root@ken1 ken1]# docker volume ls
DRIVER VOLUME NAME
local b0cfa7ae0abe933392c3e649f3d0bec0185c8357c9673ebc0322920cdab8235e
 
验证总结:
两个容器如果共享了一个数据卷的话,删除一个容器的时候即使加上-v选线的话,即使删除源容器的话数据卷并不会被删除。

 

Guess you like

Origin www.cnblogs.com/itzhao/p/11354213.html