12

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?

jwknz
  • 6,598
  • 16
  • 72
  • 115

3 Answers3

6

I don't think you can do it without a container. You need something along the lines of this documentation 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
Sync
  • 3,571
  • 23
  • 30
Marc
  • 436
  • 3
  • 4
  • This worked for me in the end with all my other building blocks I had. Thanks for the solution – jwknz Apr 15 '19 at 09:24
  • If you created the volume with Docker-Compose, prefix it with the foldername. You can check the volumes with 'docker volume ls'. – Hugo Logmans May 12 '20 at 09:01
1

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/
Cuong DaoVan
  • 262
  • 2
  • 6
  • Yes I have used compose - is that the only way I can access the volume though? Or can I access the Volume directly without a container present? – jwknz Apr 10 '19 at 02:15
  • Yeah that access the folder on my host machine, but it doesn't access the volume. I want to have a format like this: host-folder => docker-volume => docker-container – jwknz Apr 10 '19 at 02:21
  • 1
    Cool and if I can access the volume without having load a container that would be better. I want the volume to be decoupled from the container. Since docker creates the volume and leaves it on my machine unless I specifically delete it, I must be able to access it right? – jwknz Apr 10 '19 at 02:24
1

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/
Romanow
  • 19
  • 5
  • 4
    When I type screen tty I get : [screen is terminating] My containers are running and I'm in the right directory. I tried also as root. Any tip? Thanks – Giggioz Aug 06 '20 at 07:56
  • 2
    @Giggioz: the code `screen /Users/$USER/Library/Containers/com.docker.docker/Data/vms/0/tty` doesn't work, check this: **[docker/for-mac](https://github.com/docker/for-mac/issues/4822)** __and__ **[link](https://stackoverflow.com/questions/63445657/why-i-am-getting-screen-is-terminating-error-in-macos/63595817#63595817)** – Romanow Dec 13 '20 at 10:50