在MacOS上访问Docker Volume内容 [英] Accessing Docker Volume content on MacOS

查看:120
本文介绍了在MacOS上访问Docker Volume内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Mac上执行 docker卷检查< dockerid> 时,我可以看到数据的路径,它显示为/var/lib/docker/volumes/<卷名>

在Mac上,此链接不存在,因为docker在非常小的VM内运行.

我可以使用 screen〜/Library/Containers/com.docker.docker/Data/vms/0/tty 进入vm,然后导航到该文件夹​​以查看卷./p>

所有这些都可以了,但是我的问题是:如何在主机上链接这些卷中的内容?

我已经尝试过: docker run -it --volume hello:/hello2 --name access_volumes busybox:latest/bin/sh 其中hello是我创建的卷的名称./p>

我可以将主机上的文件夹链接到容器,但是我想从主机上备份内容或编辑卷的内容.

我该怎么做?

解决方案

我认为没有容器就无法做到.您需要遵循 https://docs的内容.docker.com/storage/#backup-restore-or-migrate-data-volumes 进行备份:

  docker run --rm --volume hello:/data -v $ {pwd):/backup busybox tar cvf/backup/backup.tar/dbdata 

或用于修改:

  docker run -d --name access_volume --volume hello:/data busybox泊坞窗cp access_volume:/data本地数据#修改本地数据泊坞窗cp本地数据access_volume:/data 

When I do a docker volume inspect <dockerid> on a Mac, I can see the path to the data, this appears as a /var/lib/docker/volumes/<volume name>

On a Mac, this link does not exist, because docker runs on inside a very tiny VM.

I can use screen ~/Library/Containers/com.docker.docker/Data/vms/0/tty to get into the vm and then navigate to the folder to see the volumes.

So got all that, but my question is: How do I link what is in these volumes on my host machine?

I have tried this: docker run -it --volume hello:/hello2 --name access_volumes busybox:latest /bin/sh Where hello is the name of a volume I have created.

I can link a folder on my host machine to the container, but I want to backup the content or edit the content of the Volume from my host machine.

How do I do that?

解决方案

I don't think you can do it without a container. You need something along the lines of https://docs.docker.com/storage/#backup-restore-or-migrate-data-volumes for backup:

docker run --rm --volume hello:/data -v $(pwd):/backup busybox tar cvf /backup/backup.tar /dbdata

or for modifying:

docker run -d --name access_volume --volume hello:/data busybox
docker cp access_volume:/data local-data
# modify local-data
docker cp local-data access_volume:/data

这篇关于在MacOS上访问Docker Volume内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆