【容器】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

 

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

eponia

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值