问题描述:

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

 

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐