docker下的数据卷的挂载

在没有指定容器挂载时,物理机会随机给容器分配数据卷进行数据存储

[root@foundation23 _data]# docker run -d --name vm2 -v /usr/share/nginx/html nginx
e0b66e1a0226750705c7feefd66bda26d6ff029836c99d69ff1d49d137c77057
[root@foundation23 _data]# docker inspect vm2 | grep vol                "Type": "volume",
                "Source": "/var/lib/docker/volumes/752b5941bfb1121b1af8e128c539a65b8e0da89c7bbf446e13dd4f4aadde143c/_data",
[root@foundation23 _data]# cd /var/lib/docker/volumes/752b5941bfb1121b1af8e128c539a65b8e0da89c7bbf446e13dd4f4aadde143c/_data
[root@foundation23 _data]# ls
50x.html  index.html
[root@foundation23 _data]# cp /etc/passwd .
[root@foundation23 _data]# ls
50x.html  index.html  passwd

[root@foundation23 _data]# docker container attach vm2
root@7d4f09271c46:/data1# cd /data1/
root@7d4f09271c46:/data1# ls
passwd

docker下的数据卷的挂载_第1张图片

[root@foundation23 docker]# cp web/index.html test/
[root@foundation23 docker]# cd test/
[root@foundation23 test]# ls
Dockerfile  index.html
[root@foundation23 test]vim Dockerfile
FROM rhel7
ADD html.tar /usr/share
VOLUME ["/usr/share/nginx/html"]
~                                 
[root@foundation23 test]# mkdir ngnx
[root@foundation23 test]#vim index.html

www.westos.org</h1>

www.westos.org1>

www.westos.org</h1>

www.westos.org1> ~ [root@foundation23 test]# mkdir nginx/html [root@foundation23 test]# cp index.html nginx/html/ [root@foundation23 test]# ls Dockerfile index.html nginx [root@foundation23 test]# cd nginx/ [root@foundation23 nginx]# ls html [root@foundation23 nginx]# cd .. [root@foundation23 test]# tar cf html.tar nginx/ [root@foundation23 test]# ls Dockerfile html.tar index.html nginx

docker下的数据卷的挂载_第2张图片

[root@foundation23 test]# docker build -t rhel7:v4 .
Sending build context to Docker daemon 15.87 kB
Step 1/3 : FROM rhel7
 ---> 0a3eb3fde7fd
Step 2/3 : ADD html.tar /usr/share
 ---> 702a511294c9
Removing intermediate container f1a0f8b8e75b
Step 3/3 : VOLUME /usr/share/nginx/html
 ---> Running in d86cf7a45725
 ---> b177620602bc
Removing intermediate container d86cf7a45725
Successfully built b177620602bc
[root@foundation23 test]# docker rm -f vm1
vm1
[root@foundation23 test]# docker rm -f vmvol
Error response from daemon: No such container: vmvol
[root@foundation23 test]# docker rm -f vol
vol

docker下的数据卷的挂载_第3张图片
docker下的数据卷的挂载_第4张图片
创建数据卷。然后使用其创建容器

[root@foundation23 test]# docker create --name vol rhel7:v4 bash
cff0a96928938f0d6e86aeb6140c7c9bfbb175cadfbb6569e6600aa87b227bc4
[root@foundation23 test]# docker run -d --name vm1 --volumes-from vol nginx
75e167dda70df25ba1a3587ab64b7f25defe2f68bf4e964a6a13bb26b86c542c
[root@foundation23 test]# docker inspect vm1
[root@foundation23 test]# curl 172.17.0.3

www.westos.org

www.westos.org

www.westos.org

www.westos.org

docker下的数据卷的挂载_第5张图片

你可能感兴趣的:(docker)