【容器】Docker之Mac下host與container之間Volume映射問題

問題描述:

Mac下運行docker容器時,其卷掛載方式與在普通Linux上不同,普通Linux上host與container之間Volume映射關係可參考這篇文章。本文中container的名字是graphite,用命令行查看container的volume掛載情況:

➜  ~ docker inspect graphite

...
...
"Mounts": [
            {
                "Type": "volume",
                "Name": "5676877cb2df79ee28190c1be5f44eb7a4b6cae2b73d4c8d450d5408935015a4",
                "Source": "/var/lib/docker/volumes/5676877cb2df79ee28190c1be5f44eb7a4b6cae2b73d4c8d450d5408935015a4/_data",
                "Destination": "/opt/graphite/conf",
                "Driver": "local",
                "Mode": "",
                "RW": true,
                "Propagation": ""
            },
            ...
            ...
          ]

可見host的volume是:

"/var/lib/docker/volumes/5676877cb2df79ee28190c1be5f44eb7a4b6cae2b73d4c8d450d5408935015a4/_data"

對應到container中的volume是:

"/opt/graphite/conf"

此時如果嘗試進入host上對應的目錄會出錯,提示目錄不存在:

➜  ~ cd /var/lib/docker/volumes/5676877cb2df79ee28190c1be5f44eb7a4b6cae2b73d4c8d450d5408935015a4/_data
cd: no such file or directory: /var/lib/docker/volumes/5676877cb2df79ee28190c1be5f44eb7a4b6cae2b73d4c8d450d5408935015a4/_data

解決方法:

在Mac OS下,進入以下目錄

~/Library/Containers/com.docker.docker/Data/vms/0/

可以看到目錄下有一個tty設備,screen連接進去,host對應的volume可以在這個linux實例中找到,進入該目錄,其中的文件與container中的/opt/graphite/conf目錄下的內容一致:

➜ ~ cd ~/Library/Containers/com.docker.docker/Data/vms/0
➜  0 ll
total 9853192
srwxr-xr-x  1 chenxi  staff     0B Sep 20 14:25 00000002.000005f4
srwxr-xr-x  1 chenxi  staff     0B Sep 20 14:25 00000002.00001000
srwxr-xr-x  1 chenxi  staff     0B Sep 20 14:25 00000002.00001001
srwxr-xr-x  1 chenxi  staff     0B Sep 20 14:25 00000003.000005f5
srwxr-xr-x  1 chenxi  staff     0B Sep 20 14:25 00000003.00000948
-rw-r--r--@ 1 chenxi  staff    60G Sep 20 15:29 Docker.raw
-rw-r--r--  1 chenxi  staff    92K Sep 20 14:25 config.iso
srwxr-xr-x  1 chenxi  staff     0B Sep 20 14:25 connect
lrwxr-xr-x  1 chenxi  staff    17B Sep 20 14:25 guest.000005f5 -> 00000003.000005f5
lrwxr-xr-x  1 chenxi  staff    17B Sep 20 14:25 guest.00000948 -> 00000003.00000948
-rw-r--r--  1 chenxi  staff   2.2K Sep 20 14:25 hyperkit.json
-rw-r--r--  1 chenxi  staff     5B Sep 20 14:25 hyperkit.pid
drwxr-xr-x  2 chenxi  staff    64B Aug 21 15:26 log
-rw-r--r--  1 chenxi  staff    36B Aug 21 15:26 nic1.uuid
lrwxr-xr-x  1 chenxi  staff    12B Sep 20 14:25 tty -> /dev/ttys006
➜  0 screen tty

####下面進入了linux實例####

linuxkit-025000000001:~#
linuxkit-025000000001:~#
linuxkit-025000000001:~# cd /var/lib/docker/volumes/5676877cb2df79ee28190c1be5f44eb7a4b6cae2b73d4c8d450d5408935015a4/_data
linuxkit-025000000001:/var/lib/docker/volumes/5676877cb2df79ee28190c1be5f44eb7a4b6cae2b73d4c8d450d5408935015a4/_data#ls -l
total 144
-rw-r--r--    1 root     root          1477 Sep  5 20:16 aggregation-rules.conf
-rw-r--r--    1 root     root          1798 Sep 16 19:04 aggregation-rules.conf.example
-rw-r--r--    1 root     root           274 Sep  5 20:16 blacklist.conf
-rw-r--r--    1 root     root           492 Sep 16 19:04 blacklist.conf.example
-rw-r--r--    1 root     root          2593 Sep  5 20:16 carbon.amqp.conf
-rw-r--r--    1 root     root          2596 Sep 16 19:04 carbon.amqp.conf.example
-rw-r--r--    1 root     root         27458 Sep  5 20:16 carbon.conf
-rw-r--r--    1 root     root         29876 Sep 16 19:04 carbon.conf.example
-rw-r--r--    1 root     root          1892 Sep  5 20:16 dashboard.conf
-rw-r--r--    1 root     root          1891 Sep 16 19:04 dashboard.conf.example
-rw-r--r--    1 root     root           729 Sep  5 20:16 graphTemplates.conf
-rw-r--r--    1 root     root          2445 Sep 16 19:04 graphTemplates.conf.example
-rwxr-xr-x    1 root     root            90 Sep 16 19:04 graphite.wsgi.example
-rw-r--r--    1 root     root           873 Sep  5 20:16 relay-rules.conf
-rw-r--r--    1 root     root           888 Sep 16 19:04 relay-rules.conf.example
-rw-r--r--    1 root     root           558 Sep  5 20:16 rewrite-rules.conf
-rw-r--r--    1 root     root           558 Sep 16 19:04 rewrite-rules.conf.example
-rw-r--r--    1 root     root           988 Sep  5 20:16 storage-aggregation.conf
-rw-r--r--    1 root     root           827 Sep 16 19:04 storage-aggregation.conf.example
-rw-r--r--    1 root     root           881 Sep  5 20:16 storage-schemas.conf
-rw-r--r--    1 root     root          1040 Sep 16 19:04 storage-schemas.conf.example
-rw-r--r--    1 root     root           315 Sep  5 20:16 whitelist.conf
-rw-r--r--    1 root     root           315 Sep 16 19:04 whitelist.conf.example

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章