Volume container which is a container that can provide volume for other container.
Volume container can provide bind mount or docker managed volume.
In this lab, I will show both.
1. Creating a volume container called VC_Data.
peter@peter-KVM:~$ sudo docker create --name VC_Data \ > -v ~/htdocs:/usr/local/apache2/htdocs \ > -v /other/useful/tools \ > busybox 5086288f2b1062e4815c692c7b2ed63dd42d61cad062d9b3f8666fc19f022d5b peter@peter-KVM:~$
2. Verify. you can see two mount types.
peter@peter-KVM:~$ docker inspect VC_Data "Mounts": [ { "Type": "bind", "Source": "/home/peter/htdocs", "Destination": "/usr/local/apache2/htdocs", "Mode": "", "RW": true, "Propagation": "rprivate" }, { "Type": "volume", "Name": "16f959d6cdb2b83f962ac0507650b16df93c8e954bb60dc30862d45d7571e27d", "Source": "/var/lib/docker/volumes/16f959d6cdb2b83f962ac0507650b16df93c8e954bb60dc30862d45d7571e27d/_data", "Destination": "/other/useful/tools", "Driver": "local", "Mode": "", "RW": true, "Propagation": "" } ],
3. Other containers can use this volume container.
peter@peter-KVM:~$ docker run --name WEB_1 -d -p 80 --volumes-from VC_Data httpd 9873cb7042b40083f519ffe648ddcbba73c286bd62ea8bc035de0a0dd43c9c22 peter@peter-KVM:~$ peter@peter-KVM:~$ docker run --name WEB_2 -d -p 80 --volumes-from VC_Data httpd 5ca16137a5d3cd67e950eb10fafa4ed5eef2f971b35ce40ba1d55facdfd8c0de peter@peter-KVM:~$ peter@peter-KVM:~$ docker inspect WEB_1 "Mounts": [ { "Type": "bind", "Source": "/home/peter/htdocs", "Destination": "/usr/local/apache2/htdocs", "Mode": "", "RW": true, "Propagation": "rprivate" }, { "Type": "volume", "Name": "16f959d6cdb2b83f962ac0507650b16df93c8e954bb60dc30862d45d7571e27d", "Source": "/var/lib/docker/volumes/16f959d6cdb2b83f962ac0507650b16df93c8e954bb60dc30862d45d7571e27d/_data", "Destination": "/other/useful/tools", "Driver": "local", "Mode": "", "RW": true, "Propagation": "" } ],
4. Verify. You can see. When I change the docker host file, the WEB_1 and WEB_2 file also will be changed.
peter@peter-KVM:~$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 5ca16137a5d3 httpd "httpd-foreground" 5 minutes ago Up 5 minutes 0.0.0.0:32769->80/tcp WEB_2 9873cb7042b4 httpd "httpd-foreground" 6 minutes ago Up 6 minutes 0.0.0.0:32768->80/tcp WEB_1 peter@peter-KVM:~$ peter@peter-KVM:~$ sudo echo "This content is from a volume container" > ~/htdocs/index.html [sudo] password for peter: peter@peter-KVM:~$ peter@peter-KVM:~$ curl 127.0.0.1:32768 This content is from a volume container peter@peter-KVM:~$ peter@peter-KVM:~$ curl 127.0.0.1:32769 This content is from a volume container peter@peter-KVM:~$
最初發表 / 最後更新: 2019.06.02 / 2019.06.02
0 comments:
張貼留言