docker数据卷容器
数据卷容器:
命名的容器挂载数据卷,其他容器通过挂载这个容器实现数据共享,挂载数据卷的容器,叫做数据卷容器。
[email protected]:/etc/docker# cat dockerfile
FROM ubuntu
MAINTAINER haojie
#RUN 执行以下命令
RUN apt-get update
RUN apt-get install iputils-ping -y
RUN apt-get install iptables -y
RUN apt-get install net-tools -y
VOLUME ["/data1","/data2"]
[email protected]:/etc/docker# docker build -t ubuntu:datavolume .
Sending build context to Docker daemon 5.12kB
Step 1/7 : FROM ubuntu
---> 2ca708c1c9cc
Step 2/7 : MAINTAINER haojie
---> Using cache
---> 80a013902529
Step 3/7 : RUN apt-get update
---> Using cache
---> d31ef5a6b63f
Step 4/7 : RUN apt-get install iputils-ping -y
---> Using cache
---> 1f49c6834bdd
Step 5/7 : RUN apt-get install iptables -y
---> Using cache
---> 3697b4c0aaea
Step 6/7 : RUN apt-get install net-tools -y
---> Using cache
---> 77c406b5943f
Step 7/7 : VOLUME ["/data1","/data2"]
---> Running in 57e4ad1caad1
Removing intermediate container 57e4ad1caad1
---> 65d4da4e2e31
Successfully built 65d4da4e2e31
Successfully tagged ubuntu:datavolume
[email protected]:/etc/docker# docker run -it -d --name myos1 ubuntu:datavolume /bin/bash
17f89ea55c7c1be3c234a9ad44f8b7188deeba1150ad74b6d8933c6770a16898
[email protected]:/etc/docker# docker exec -it myos1 /bin/bash
[email protected]:/# touch /data1/abc
[email protected]:/# exit
exit
[email protected]:/etc/docker# docker run -it -d --name myos2 --volumes-from myos1 ubuntu:datavolume /bin/bash
529a94c2215426003f5604786aa666c58a51fd8307bd00e0840bb89df88e433f
[email protected]:/etc/docker# docker exec -it myos2 /bin/bash
[email protected]:/# ls /
bin boot data1 data2 dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
[email protected]:/# ls /data1/
abc
[email protected]:/# touch /data1/bcd
[email protected]:/# exit
exit
[email protected]:/etc/docker# docker run -it -d --name myos3 --volumes-from myos1 ubuntu:datavolume /bin/bash
cf7b503dd2186489cd61664a1d5df9dfbe33060f612f42f8989483daf3d94800
[email protected]:/etc/docker# docker exec -it myos3 /bin/bash
[email protected]:/# ls /data1
abc bcd
[email protected]:/# exit
exit