Host path of volume

Expected behavior

$ docker volume inspect --format '{{ .Mountpoint }}' repo
/var/lib/docker/volumes/repo/_data

Then, should be exact folder on Mac. 

Actual behavior

$ docker volume inspect --format '{{ .Mountpoint }}' repo
/var/lib/docker/volumes/repo/_data
$ ls /var/lib/docker
ls: /var/lib/docker: No such file or directory

Information

  • Want to know actual path on Mac.
  • With the Mac version, the docker’s any paths which starts from “/var/lib” doesn’t match with any other folders on the Mac.
  • Try to search on ~/Library/Container/com.docker.docker and ~/Documents/Kinematic, but I couldn’t find.

Steps to reproduce the behavior

2 Likes

You need to keep in mind that Docker is still running inside a VM. The system paths are still relative to the VM, and not to your Mac.
Only some folders are already mounted from your Mac into the VM. You can get an overview by running this command:

$ docker run --rm -it -v /:/vm-root alpine:edge ls -l /vm-root
2 Likes

Thank you for the information.

I got your point. The above paths are the main VM’s path, neither docker instance or Mac.

What I want to know is, the volumes created by “docker volume create” should exist as a type of file or folder on the Mac filesystem, and I couldn’t find it. That’s what I’m looking for.

I’ll use this information for file backup. And I can backup it if I know the exact location of file.

2 Likes

Ah, now I understand.

That thread could give you some hints: No space left on device error

You probably won’t find the volumes in folders there, but only some huge files.

Good hint.

Regarding shared thread, I think I need to wait next version of Docker so that I can decide how to backup or which I should backup. Looks like this file is qemu image, but seems it’s just temp file because Docker staff(engineer?) recommends if this sparse image size increase to maximum, then just delete it then restart docker application.

Finally, I need another trial to back up data files in volume container.

Thank you.

@riverful You are not required to take a backup of the full qemu image, if that is not your requirement. I suspect some people will be interested in backing-up specific volumes or specific files and directories inside a volume. For these people, a full qemu-file backup is too much, they need more granularity and control over what will be backed-up.

On the topic:

My understanding is that, at the moment, it is a matter of getting onto the Docker host and backing up the folders. Make sense and it is simple enough.

For instance, the local docker volume ls command and the ls command on the Docker host should give you the same result (afaik):

$ docker volume ls
DRIVER              VOLUME NAME
local               04576d248c19b1210d47e94c8211493428cd3c3aa71dfe3fa0f4214589a6f875
local               31af0f01492d8f7b832dad75e731b754302e84fbecfa7c654d7de10465bec204
local               8c511e67b2859e33493798eacf5db901ca40f6dd43725c5472c0c931fb408442
etc.

$ screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty  
#user: root
#password: <none>
$ ls -ltrh /var/lib/docker/volumes
total 148
drwxr-xr-x    3 root     root          4096 May 16 13:20 04576d248c19b1210d47e94c8211493428cd3c3aa71dfe3fa0f4214589a6f875
drwxr-xr-x    3 root     root          4096 May 16 13:20 31af0f01492d8f7b832dad75e731b754302e84fbecfa7c654d7de10465bec204
drwxr-xr-x    3 root     root          4096 May 16 13:20 8c511e67b2859e33493798eacf5db901ca40f6dd43725c5472c0c931fb408442
etc.

So on the Docker host, I can imagine a backup agent running (or a backup agent connecting to that host) and taking a standard file-based backup of the volumes you’d like to back-up.

Good luck!

3 Likes

To add on top of @aleveille’s suggestion: if you don’t prefer to screen ... into the Docker VM, you can use mounts from /Users/ and /var/lib/docker/ to perform backups, e.g. like this:

docker run --rm -it -v /Users/<username>/volume-backup:/backup -v /var/lib/docker:/docker alpine:edge tar cfz /backup/volumes.tgz /docker/volumes/

Maybe there will be an easy way to add volume plugins so that we don’t have to manually access the VM’s file system.

2 Likes

Both are great information.

aleveille’s explanation is very clear to understand what I’m face with. It makes sense the hash number from volume ls exists as actual file name of /var/lib/docker/volumes in docker itself. I think it’s safe to say both are identical and I can imagine how to make the strategy for backup. Thanks.

Regarding the example of @gesellix, it’s enough for me to utilize it right now. Based on this, I can make the useful scripts for my enviroment. Thanks, too.

And, today I saw the news about newly updated docker beta. Let’s have fun. :slight_smile:

hey thanks @riverful for ask, and thanks @aleveille for your replies. At ubuntu I just used to find /var/lib/docker but trying to locate the volumes using Docker beta for Mac is resulting kind of difficult to understand all about that Docker VM

Anyway thanks guys.

OS: macOS High Sierra Version 10.13.2
Docker version: 17.09.1-ce, build 19e2cf6

I was following an example in a book to learn about how volumes work and came across this as well. On my version of docker, it is running from~/Library/Containers/com.docker.docker and you can run screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty to get into the shell. Then you can run ls /var/lib/docker/volumes

5 Likes

Thanks Seet, this helped.

On my Mac the tty file is at “~/Library/Containers/com.docker.docker/Data/vms/0” - so anyone looking for this, be mindful of the changing directory - you need to look for tty file.

Great info, i manage to ssh to the vm within the mac and could operate the volume.

How do I find out where the volume is on a Windows machine?

When I try to run the screen command, it says:
bash: screen: command not found

Thank you so much that worked for me

For those who have Docker Desktop for Mac and don’t have that tty file nowhere, here you have a couple of fresh solutions:

The command does not work for me. I get a message: cannot exec screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty

I’m using docker desktop version 4.0.1

Path no longer works for Mac M1 Monerey :confused: Fortunately, volumes can be seen in Visual Code Studio with Docker extension or Docker Mac app Dashboard. Still I’d prefer direct fs access that would give more flexibility… hope it’s still accessible via fs in /var/lib/docker/volumes on linux distributions in UAT or PRODuction environments.

Problem still actual.

Workaround: docker can't access to volume with screen · Issue #4822 · docker/for-mac · GitHub