理論+實操:docker掛載


在這裏插入圖片描述

一:docker數據卷

數據卷:掛載宿主系統的存儲空間

[root@gsy ~]# docker run -v /test1:/test1 --name test1 -it centos:7 /bin/bash
[root@4e5fdf54c872 /]# cd /test1/
[root@4e5fdf54c872 test1]# echo "test1" > test1
[root@4e5fdf54c872 test1]# ls  
test1
[root@4e5fdf54c872 test1]# cat test1 
test1

返回宿主系統查看

[root@4e5fdf54c872 test1]# exit
exit
[root@gsy ~]# cd /test1/
[root@gsy test1]# ls
test1
[root@gsy test1]# cat test1 
test1
[root@gsy test1]# 

二:數據卷容器

數據卷容器:掛載容器的存儲空間

2.1 創建數據卷容器test2

[root@gsy test1]# docker run --name test2 -v /data1 -v /data2 -it centos:7 /bin/bash
[root@8dcf772df2ac /]# exit

2.2 創建新容器db1並掛載數據卷容器目錄

[root@gsy test1]# docker run -it --volumes-from test2 --name db1 centos:7 /bin/bash
[root@fe4968194091 /]# 

2.3 測試

[root@fe4968194091 /]# ls
anaconda-post.log  bin  data1  data2  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  test2  tmp  usr  var
[root@fe4968194091 /]# cd data1
[root@fe4968194091 data1]# echo "test2" > test2
[root@fe4968194091 data1]# cd /data2
[root@fe4968194091 data2]# echo "test2" > test2
[root@fe4968194091 data2]# exit

2.4 查看數據卷容器test2

[root@gsy test1]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                       PORTS                    NAMES
fe4968194091        centos:7            "/bin/bash"              2 minutes ago       Exited (0) 39 seconds ago                             db1
8dcf772df2ac        centos:7            "/bin/bash"              4 minutes ago       Exited (127) 3 minutes ago                            test2
4e5fdf54c872        centos:7            "/bin/bash"              30 minutes ago      Exited (0) 28 minutes ago                             test1
72c7470e210c        registry            "/entrypoint.sh /etc…"   51 minutes ago      Up 51 minutes                0.0.0.0:5000->5000/tcp   determined_lamport
[root@gsy test1]# docker start 8dcf772df2ac
8dcf772df2ac
[root@gsy test1]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS                    NAMES
fe4968194091        centos:7            "/bin/bash"              6 minutes ago       Exited (0) 3 minutes ago                             db1
8dcf772df2ac        centos:7            "/bin/bash"              7 minutes ago       Up 3 seconds                                         test2
4e5fdf54c872        centos:7            "/bin/bash"              33 minutes ago      Exited (0) 31 minutes ago                            test1
72c7470e210c        registry            "/entrypoint.sh /etc…"   54 minutes ago      Up 54 minutes               0.0.0.0:5000->5000/tcp   determined_lamport
[root@gsy test1]# docker exec -it 8dcf772df2ac  /bin/bash
[root@8dcf772df2ac /]# ls
anaconda-post.log  bin  data1  data2  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
[root@8dcf772df2ac /]# cat data1/test2 
test2
[root@8dcf772df2ac /]# cat data2/test2 
test2
[root@8dcf772df2ac /]# 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章