Accessing Docker Volume content on MacOS

余生长醉 提交于 2021-01-17 04:56:35

问题


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?


回答1:


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



回答2:


for example, you create a Volume with a File Docker-Compose.yml:

...

influxdb:
 image: influxdb:latest
 container_name: influxdb
 restart: always
 ports:
   - "8086:8086"
   - "9092:9092"
 volumes:
  - type: volume
    source: vol_influxdb
    target: /var/lib/influxdb

...

You can't find this Volume "vol_influxdb" on your Mac, because it's in the Docker-VM. Start your Mac-Terminal an Enter:

screen /Users/<username>/Library/Containers/com.docker.docker/Data/vms/0/tty 

Now you are in the Docker-VM and you can search your Volume with:

cd /var/lib/docker/volumes/<VolumeName>/_data/



回答3:


Have you known docker-compose: you can link your folder to the container by volumes you can link like this

volumes:
  - ./your_host_folder:/folder_in_container/


来源:https://stackoverflow.com/questions/55603421/accessing-docker-volume-content-on-macos

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!