1. 程式人生 > >易學筆記-第6章 資料管理/6.1 資料卷掛載

易學筆記-第6章 資料管理/6.1 資料卷掛載

  • 資料卷
  1. 在容器內建立資料卷,掛載目錄為 wys:

    [[email protected] ~]# docker run -d -P --name mydatadocker -v /wys docker.io/ubuntu:latest 容器名字為mydatadocker,掛載目錄為wys  -P表示容器暴露介面,不知道為什麼這種方式建立的容器都是exit狀態的

    b7cf1f9433c8164f0045248c0138af4910557b7e2a9275706996bcbab738d478

    [[email protected] localwys]# docker run  -it  --name datadocker  -v /dbdata  docker.io/ubuntu:latest

    [email protected]:/# ls  這種方式建立的資料卷可以進入管理端

    [[email protected] localwys]# docker exec -it 0e834d9f80ce /bin/bash

    [email protected]:/# quit

  2. 掛載本地目錄到資料卷,這樣可以在本地存在一些程式,然後再容器中執行和使用

    [[email protected] ~]# docker run -tid  -P --name mydatadocker -v /app/localwys:/wys docker.io/ubuntu:latest 

    容器名字為mydatadocker/localwys為本地目錄, wys為容器目錄  -P表示容器暴露介面,

    71abfc616acd626a09ab6a9cc3396c37fc3ba54b71e3977c76610abc1aabf77e

    [[email protected] ~]#

  3. 掛載本地檔案到資料卷

    [[email protected] localwys]# docker run --rm -it -v /localwys/123.txt:/wys/123.txt docker.io/ubuntu:latest /bin/bash   /localwys/123.txt

    :本地檔案 /wys/123.txt:掛載檔案

    [email protected]:/# ls

    bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var  wys

    [email protected]:/# cd wys

    [email protected]:/wys# ls

    123.txt

  4. 掛載本地檔案和本地目錄的建議:
  5. 檢視容器掛載的資料卷

    [[email protected] ~]# docker inspect aeb2785fdde1 | grep Mounts -A 20 aeb2785fdde1為容器ID

            "Mounts": [

                {

                    "Type": "bind",

                    "Source": "/app/registry",

                    "Destination": "/tmp/registry",

                    "Mode": "",

                    "RW": true,

                    "Propagation": "rprivate"

                },

                {

                    "Type": "volume",

                    "Name": "a6678595269774389931b290767a3652b3a638efadf48035abade9f33ea88646",

                    "Source": "/var/lib/docker/volumes/a6678595269774389931b290767a3652b3a638efadf48035abade9f33ea88646/_data",

                    "Destination": "/var/lib/registry",

                    "Driver": "local",

                    "Mode": "",

                    "RW": true,

                    "Propagation": ""

                }

            ],

            "Config": {