docker的資料卷管理

來源:互聯網
上載者:User

標籤:docker

  1. mkdir  -p  /data/volumes

  2. 掛載目錄

[[email protected] ~]# docker run -d  --name nginx-volumes   -v  /data/volumes:/data  nginx 1263f51d5bd1114c7f1582a0efb68266ce367629f01a64693cd15cf115165392本地的  /data/volumes   掛載到容器的/data  目錄下

3.進入容器寫檔案測試

[[email protected] ~]# docker ps -a CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                               NAMES1263f51d5bd1        nginx               "nginx -g ‘daemon off"   5 minutes ago       Up 5 minutes        80/tcp, 443/tcp                     nginx-volumesa04f5eee61b5        nginx               "nginx -g ‘daemon off"   15 minutes ago      Up 15 minutes       443/tcp, 59.110.25.215:89->80/tcp   dokcer-volumes1f3d2f356995        nginx               "nginx -g ‘daemon off"   41 minutes ago      Up 41 minutes       443/tcp, 59.110.25.215:88->80/tcp   mynginx[[email protected] ~]# bash dockerin.sh 1f3d2f356995[email protected]:/# cd  /data[email protected]:/data# ls[email protected]:/data# touch   test01  test02[email protected]:/data# lstest01test02[email protected]:/data#

4.linux本機查看

[[email protected] volumes]# lltotal 0-rw-r--r-- 1 root root 0 Jan  3 22:16 test01-rw-r--r-- 1 root root 0 Jan  3 22:16 test02[[email protected] volumes]# pwd/data/volumes[[email protected] volumes]#

5.掛載多個目錄

[[email protected] volumes]# docker run  -d --name nginx-volumes02  -v /data/volumes2:/data/volumes2  -v  /data/volumes3:/data/volumes3 nginx 5b33955e8addab36c3c183a754d7f82e3ba6c94f1b865d1f4ef366af8ba9e67b[[email protected] volumes]# [[email protected] ~]# bash dockerin.sh 5b33955e8addab36c[email protected]:/# cd /data/[email protected]:/data# lsvolumes2  volumes3[email protected]:/data# touch  volumes2/002[email protected]:/data# touch  volumes3/003[email protected]:/data# 也是完全OK的[[email protected] data]# tree   .├── volumes│   ├── test01│   └── test02├── volumes2│   └── 002└── volumes3    └── 0033 directories, 4 files[[email protected] data]#

6.docker的劵共用機制

[[email protected] data]# docker run -d --name nginx-volumes-from --volumes-from nginx-volumes02 nginx 3342b2a88ba7121ec19e66fc388d8a19e5499e93fe786452bba295f66c9a1904 nginx-volumes02是一個容器,此容器掛載了兩個目錄 那麼nginx-volumes-from將繼承nginx-volumes02的目錄,不管nginx-volumes02是否運行 [[email protected] ~]# bash dockerin.sh  3342b2a88ba7121e [email protected]:/data# cd volumes2[email protected]:/data/volumes2# ls002[email protected]:/data/volumes2# touch 00vo[email protected]:/data/volumes2# cd  ../[email protected]:/data# lsvolumes2  volumes3[email protected]:/data# cd volumes3[email protected]:/data/volumes3# ls003[email protected]:/data/volumes3# touch 003vo[email protected]:/data/volumes3#   linux系統查看[[email protected] data]# tree .├── volumes│   ├── test01│   └── test02├── volumes2│   ├── 002│   └── 00vo└── volumes3    ├── 003    └── 003vo3 directories, 6 files[[email protected] data]#


本文出自 “磚家部落格” 部落格,請務必保留此出處http://wsxxsl.blog.51cto.com/9085838/1888733

docker的資料卷管理

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.