The path to docker's volumes in Ubuntu

I'm both new to Ubuntu and Docker. I cut to the chase, when I create a volume using the sudo docker volume create TEST command, where should I expect to find the TEST volume and its data in my hard drive?

If I want it to be located in another drive, lets say D:\ (still new to ubuntu not sure if it also applies to linux) drive, what do I have to do?


Solution 1:

Looks like it is /var/lib/docker/volumes

Here's what I got:

$ docker volume create TEST 
$ ls /var/lib/docker/volumes
metadata.db  TEST/

Solution 2:

Use docker volume inspect TEST (docs), and there will be a key "Mountpoint" with the path to it:

$ docker volume inspect TEST
[
    {
        "CreatedAt": "2020-09-18T10:46:55-07:00",
        "Driver": "local",
        "Labels": {},
        "Mountpoint": "/var/lib/docker/volumes/TEST/_data",
        "Name": "TEST",
        "Options": {},
        "Scope": "local"
    }
]

To extract just the path, for example to use in a script:

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