277

I'm trying to learn docker at the moment and I'm getting confused about where data volumes actually exist.

I'm using Docker Desktop for Windows. (Windows 10)

In the docs they say that running docker inspect on the object will give you the source:https://docs.docker.com/engine/tutorials/dockervolumes/#locating-a-volume

$ docker inspect web

"Mounts": [
    {
        "Name": "fac362...80535",
        "Source": "/var/lib/docker/volumes/fac362...80535/_data",
        "Destination": "/webapp",
        "Driver": "local",
        "Mode": "",
        "RW": true,
        "Propagation": ""
    }
]

however I don't see this, I get the following:

$ docker inspect blog_postgres-data
[
    {
        "Driver": "local",
        "Labels": null,
        "Mountpoint": "/var/lib/docker/volumes/blog_postgres-data/_data",
        "Name": "blog_postgres-data",
        "Options": {},
        "Scope": "local"
    }
]

Can anyone help me? I just want to know where my data volume actually exists is it on my host machine? If so how can i get the path to it?

schnatterer
  • 7,525
  • 7
  • 61
  • 80
Brad
  • 8,044
  • 10
  • 39
  • 50
  • did you find the solution to see where they "actually" stored ? It is very easy in Docker toolbox to verify, we can log in to the docker-machine and check. However, I didn't find a way yet to verify where those volumes exist in the case of Docker Desktop – Nag Mar 24 '20 at 09:06
  • 2
    See the accepted answer – Brad Mar 24 '20 at 12:31

19 Answers19

605

I am Windows + WSL 2 (Ubuntu 18.04).

Type in the Windows file explorer :

  • For Docker version 20.10.+ : \\wsl$\docker-desktop-data\data\docker\volumes
  • For Docker Engine v19.03: \\wsl$\docker-desktop-data\version-pack-data\community\docker\volumes\

You will have one directory per volume.

Sarye Haddadi
  • 6,346
  • 2
  • 13
  • 12
  • 31
    Holy mother, I cannot believe how long it took before I found your answer and the solution. I looked in a ridiculous number of places. I guess this is a brand new thing. Thanks so much. – Sarel Botha Oct 24 '20 at 17:44
  • 19
    More generally `/var/lib/docker/` maps to ``\\wsl$\docker-desktop-data\version-pack-data\community\docker\`` – David Dec 05 '20 at 22:19
  • 2
    Very confusing - this was correct for me as well. – Pixelartist Dec 20 '20 at 21:02
  • 6
    This worked for me, but I am also wondering if this is explicitly documented anywhere in the official docs. – wlnirvana Apr 18 '21 at 01:24
  • @wlnirvana yeah like what the heck? Do the folks at Docker assume we don't care about losing our data? – gargoylebident Apr 21 '22 at 21:52
  • Found mine in `\\wsl$\docker-desktop-data\data\docker\volumes`. Not sure why my path is different. – dibery Jun 15 '22 at 07:05
  • @dibery: you may have a newer version of Docker. Could you please share your Docker version – Sarye Haddadi Jun 15 '22 at 16:57
  • Docker Desktop version 4.9.0, and Docker Engine 20.10.16. – dibery Jun 16 '22 at 01:53
  • Ok, they might have changed the directory for newer version. I edit my post with your provided information. – Sarye Haddadi Jun 17 '22 at 08:29
  • 2
    For this to work I had to enable network detection first on my Windows 10 machine otherwise I got an error message after entering the wsl$ path in the file explorer. – Bigman74066 Aug 30 '22 at 12:50
  • @wlnirvana it is irrelevant, where docker exactly stores the content of the volumes as you should not access them via their actual file location. Volumes are thought to be accessed *explicitely* from container(s). See https://docs.docker.com/storage/volumes/#backup-restore-or-migrate-data-volumes for how to backup/restore data stored in volumes. – isnot2bad Sep 30 '22 at 07:26
  • 2
    FWIW, the volumes can be accessed in the Windows paths mentioned above, but not inside the actual WSL2 through the corresponding path `/mnt/wsl/docker-desktop-data/data/`. The directory is there too, but it seems empty. – jgangso Dec 09 '22 at 08:04
84

Your volume directory is /var/lib/docker/volumes/blog_postgres-data/_data, and /var/lib/docker usually mounted in C:\Users\Public\Documents\Hyper-V\Virtual hard disks. Anyway you can check it out by looking in Docker settings.

You can refer to these docs for info on how to share drives with Docker on Windows.

BTW, Source is the location on the host and Destination is the location inside the container in the following output:

"Mounts": [
{
    "Name": "fac362...80535",
    "Source": "/var/lib/docker/volumes/fac362...80535/_data",
    "Destination": "/webapp",
    "Driver": "local",
    "Mode": "",
    "RW": true,
    "Propagation": ""
}
]

Updated to answer questions in the comment:

My main curiosity here is that sharing images etc is great but how do I share my data?

Actually volume is designed for this purpose (manage data in Docker container). The data in a volume is persisted on the host FS and isolated from the life-cycle of a Docker container/image. You can share your data in a volume by:

  • Mount Docker volume to host and reuse it

    docker run -v /path/on/host:/path/inside/container image

    Then all your data will persist in /path/on/host; you could back it up, copy it to another machine, and re-run your container with the same volume.

  • Create and mount a data container.

    Create a data container: docker create -v /dbdata --name dbstore training/postgres /bin/true

    Run other containers based on this container using --volumes-from: docker run -d --volumes-from dbstore --name db1 training/postgres, then all data generated by db1 will persist in the volume of container dbstore.

For more information you could refer to the official Docker volumes docs.

Simply speaking, volumes is just a directory on your host with all your container data, so you could use any method you used before to backup/share your data.

can I push a volume to docker-hub like I do with images?

No. A Docker image is something you can push to a Docker hub (a.k.a. 'registry'); but data is not. You could backup/persist/share your data with any method you like, but pushing data to a Docker registry to share it does not make any sense.

can I make backups etc?

Yes, as posted above :-)

tscpp
  • 1,298
  • 2
  • 12
  • 35
shizhz
  • 11,715
  • 3
  • 39
  • 49
  • Ok so the source `/var/lib/docker/volumes/blog_postgres-data/_data` is the linux VM docker is running on. My main curiosity here is that sharing images etc is great but how do I share my data? can I push a volume to docker-hub like I do with images? can I make backups etc? – Brad Apr 03 '17 at 15:15
  • @Brad, I updated my answer for your questions because comment is not enough, hope it could be helpful to you :-) – shizhz Apr 04 '17 at 01:28
  • @Brad you can mount the same named volume in multiple containers. So `docker run -it --rm -v blog_postgres-data:/data busybox ls -l /data` will show that data. – BMitch Feb 20 '19 at 13:25
  • 9
    Directory "C:\Users\Public\Documents\Hyper-V\Virtual hard disks" is empty (Wondows 10 Enterprise) – Leos Literak Aug 14 '20 at 15:45
  • But dbstore is exited. How to view/download the data?. – sushil Sep 22 '20 at 12:52
  • 2
    Directory "C:\Users\Public\Documents\Hyper-V\Virtual hard disks" is empty for me also – Gigino Nov 30 '20 at 16:20
  • 1
    Your Docker is eventually managed by Hyper-V (unless you use WSL2). It could be under ProgramData\DockerDesktop – hyamanieu Dec 15 '20 at 09:24
  • You can find it in C:\ProgramData\Docker but "ProgramData" is a hidden folder. The subfolder \volumes will contain everything you can find via "docker volume ls" – ill Feb 02 '21 at 11:20
51

For Windows 10 + WSL 2 (Ubuntu 20.04), Docker version 20.10.2, build 2291f61

Docker artifacts can be found in

DOCKER_ARTIFACTS == \\wsl$\docker-desktop-data\version-pack-data\community\docker

Data volumes can be found in

enter image description here

DOCKER_ARTIFACTS\volumes\[VOLUME_ID]\_data

enter image description here

craftsmannadeem
  • 2,665
  • 26
  • 22
  • 1
    Thanks for this. I've been struggling to find the correct path. Where did you find out the correct folder? Most answers on the web are outdated and inaccurate for the latest version, pointing to now empty/inexistent folders. – Leônidas Villeneuve Mar 02 '21 at 17:58
  • 2
    Awesome, thanks so much. For any windows user who is still confused, simply copy-paste this path \\wsl$\docker-desktop-data\version-pack-data\community\docker directly into your file explorer and it will work :D – Tanzim Chowdhury Sep 28 '21 at 12:53
  • Hey everyone, don't type in Network at the start of your file path. Just type \\wsl$ This way, you can manually navigate your way to the Docker files manually for anyone that wants to better understand how to navigate to those files. Hope this helps :) This is the resource I found to access the wsl$ https://www.ntweekly.com/2021/05/18/open-wsl-path-on-windows-explorer/ – Monttana16 Jul 27 '22 at 08:01
  • Using docker desktop v20. `docker volume inspect my_vol` shows a valid volume. \\wsl$ is empty. – dudeNumber4 Oct 04 '22 at 15:17
38

I have found that my setup of Docker with WSL 2 (Ubuntu 20.04) uses this location at Windows 10:

C:\Users\Username\AppData\Local\Docker\wsl\data\ext4.vhdx

Where Username is your username.

Konard
  • 2,298
  • 28
  • 21
  • 1
    Using docker desktop v20. `docker volume inspect my_vol` shows a valid volume. C:\Users\me\AppData\Local\Docker\wsl doesn't exist. – dudeNumber4 Oct 04 '22 at 15:22
37
\\wsl$\docker-desktop-data\version-pack-data\community\docker\volumes\

Worked for me as well (Windows 10 Home), great stuff.

G.S
  • 10,413
  • 7
  • 36
  • 52
GoldyOnline
  • 519
  • 4
  • 4
21

When running linux based containers on a windows host, the actual volumes will be stored within the linux VM and will not be available on the host's fs, otherwise windows running on windows => C:\ProgramData\Docker\volumes\

Also docker inspect <container_id> will list the container configuration, under Mounts section see more details about the persistence layer.

Update: Not applicable for Docker running on WSL.

  • 2
    Your answer is correct "When running linux based containers on a windows host, the actual volumes will be stored within the linux VM and will not be available on the host's fs" I could not find any items in "C:\Users\Public\Documents\Hyper-V\Virtual hard disks" folder. – theeranitp Jun 01 '20 at 05:35
  • And it appears that Docker Desktop is very willing to simply blow away that VM. For instance I tried to change something in the JSON file in Docker Desktop > Settings > Docker Engine and it was apparently invalid. After Docker Desktop tried to restart a few times, I happened to be watching in Hyper-V Manager and it just deleted the VM. – Aaron Axvig Jul 21 '20 at 17:26
  • @AaronAxvig wait so you just lost all of your data like that? How is that an okay thing? So they give us no ability to back it up (because the volume is apparently nowhere to be found) _and_ it can just be gone like that? What's the point of Docker again if you can just lose all your data like that? – gargoylebident Apr 21 '22 at 21:01
14

If you have wsl2 enabled, u can find it in file explorer under \\wsl$\docker-desktop\mnt\host\wsl\docker-desktop-data\data\docker

David Wild
  • 193
  • 1
  • 8
9

you can find the volume associated with host on below path for Docker Desktop(Windows)

\\wsl$\docker-desktop-data\version-pack-data\community\docker\volumes
Waqas Ahmed
  • 4,801
  • 3
  • 36
  • 45
7

In my case, i install docker-desktop on wsl2, windows 10 home. i find my image files in

\\wsl$\docker-desktop-data\version-pack-data\community\docker\overlay2
\\wsl$\docker-desktop-data\version-pack-data\community\docker

Containers, images volumes infos are all there.

All image files are stored there, and have been seperated into several folders with long string names. When i look into every folder, i can find all the real image files in "diff" folders.

Although the terminal show the path "var/lib/docker", but the folder doesn't exsit and the actual files are not stored there. i think there is no error, the "var/lib/docker" is just linked or mapped to the real folder, kind like that

Json Bourne
  • 139
  • 1
  • 1
7

If you find \\wsl$ a pain to enter or remember, there's a more GUI-friendly method in Windows 10 release 2004 and onwards. With WSL 2, you can safely navigate to all the special WSL shares via the new Linux icon in File Explorer:

Linux icon shown as the last scrollable item in the folders pane within File Explorer

From there you can drill down to (e.g.) \docker-desktop-data\data\docker\volumes, as mentioned in other answers.

\wsl.localhost\docker-desktop-data\data\docker\volumes within File Explorer

For more details, refer to Microsoft's official WSL filesystems documentation, which mentions these access methods. For the technically curious, Microsoft's deep dive video should answer a lot of questions.

Rob Pomeroy
  • 305
  • 3
  • 8
5

For me I found my volumes in

\\wsl$\docker-desktop-data\data\docker\volumes\

Using WSL2 and Windows 21H1

cclloyd
  • 8,171
  • 16
  • 57
  • 104
5

In Windows 11 with Docker Desktop v4.15.0 with WSL2 enabled, the path to navigate to the volumes folder is \\wsl.localhost\docker-desktop-data\data\docker\volumes

Carlos Torrecillas
  • 4,965
  • 7
  • 38
  • 69
3

Mounting any NTFS based directories did not work for my purpose (MongoDB - as far as I'm aware it is also the case for Redis and CouchDB at least): NTFS permissions did not allow necessary access for such DBs running in containers. The following is a setup with named volumes on HyperV.

The following approach starts an ssh server within a service, setup with docker-compse such that it automatically starts up and uses public key encryption between host and container for authorization. This way, data can be uploaded/downloaded via scp or sftp.

The full docker-compose.yml for a webapp + mongodb is below, together with some documentation on how to use ssh service:

version: '3'
services:
  foo:
    build: .
    image: localhost.localdomain/${repository_name}:${tag}
    container_name: ${container_name}
    ports:
      - "3333:3333"
    links:
      - mongodb-foo
    depends_on:
      - mongodb-foo
      - sshd
    volumes:
      - "${host_log_directory}:/var/log/app"

  mongodb-foo:
    container_name: mongodb-${repository_name}
    image: "mongo:3.4-jessie"
    volumes:
      - mongodata-foo:/data/db
    expose:
      - '27017'

  #since mongo data on Windows only works within HyperV virtual disk (as of 2019-4-3), the following allows upload/download of mongo data
  #setup: you need to copy your ~/.ssh/id_rsa.pub into $DOCKER_DATA_DIR/.ssh/id_rsa.pub, then run this service again
  #download (all mongo data): scp -r -P 2222 user@localhost:/data/mongodb [target-dir within /c/]
  #upload (all mongo data): scp -r -P 2222 [source-dir within /c/] user@localhost:/data/mongodb
  sshd:
    image: maltyxx/sshd
    volumes:
        - mongodata-foo:/data/mongodb
        - $DOCKER_DATA_DIR/.ssh/id_rsa.pub:/home/user/.ssh/keys/id_rsa.pub:ro
    ports:
        - "2222:22"
    command: user::1001

#please note: using a named volume like this for mongo is necessary on Windows rather than mounting an NTFS directory.
#mongodb (and probably most other databases) are not compatible with windows native data directories due ot permissions issues.
#this means that there is no direct access to this data, it needs to be dumped elsewhere if you want to reimport something.
#it will however be persisted as long as you don't delete the HyperV virtual drive that docker host is using.
#on Linux and Docker for Mac it is not an issue, named volumes are directly accessible from host.
volumes:
  mongodata-foo:

this is unrelated, but for a fully working example, before any docker-compose call the following script needs to be run:

#!/usr/bin/env bash
set -o errexit
set -o pipefail
set -o nounset

working_directory="$(pwd)"
host_repo_dir="${working_directory}"
repository_name="$(basename ${working_directory})"
branch_name="$(git rev-parse --abbrev-ref HEAD)"
container_name="${repository_name}-${branch_name}"
host_log_directory="${DOCKER_DATA_DIR}/log/${repository_name}"
tag="${branch_name}"

export host_repo_dir
export repository_name
export container_name
export tag
export host_log_directory

Update: Please note that you can also just use docker cp nowadays, so the sshd container outlined above is probably not necessary anymore, except if you need remote access to the file system running in a container under a Windows host.

Michel Müller
  • 5,535
  • 3
  • 31
  • 49
1

If you're searching where the data is actually located when you put a volume that is pointing to the docker "vm" like here:

version: '3.0'
services:
  mysql-server:
    image: mysql:latest
    container_name: mysql-server
    restart: always
    ports:
      - 3306:3306
    volumes:
      - /opt/docker/mysql/data:/var/lib/mysql

The "/opt/docker/mysql/data" or just the / is located in \\wsl$\docker-desktop\mnt\version-pack\containers\services\docker\rootfs

Hope it's helping :)

Zeldri
  • 21
  • 3
0

Each container has its own filesystem which is independent from the host filesystem. If you run your container with the -v flag you can mount volumes so that the host and container see the same data (as in docker run -v hostFolder:containerFolder).

The first output you printed describes such a mounted volume (hence mounts) where /var/lib/docker/volumes/fac362...80535/_data (host) is mounted to /webapp (container).

I assume you did not use -v hence the folder is not mounted and only accessible in the container filesystem which you can find in /var/lib/docker/volumes/blog_postgres-data/_data. This data will be deleted if you remove the container (docker -rm) so it might be a good idea to mount the folder.

As to the question where you can access this data from windows. As far as I know, docker for windows uses the bash subsystem in Windows 10. I would try to run bash for windows10 and go to that folder or find out how to access the linux folders from windows 10. Check this page for a FAQ on the linux subsystem in windows 10.

Update: You can also use docker cp to copy files between host and container.

G.S
  • 10,413
  • 7
  • 36
  • 52
herm
  • 14,613
  • 7
  • 41
  • 62
  • 3
    I realise this is a couple of years old, but it's probably worth pointing out that Docker for Windows does *not* presently use Windows Subsystem for Linux; rather, it runs Moby Linux inside HyperV. – al45tair May 24 '19 at 11:04
0

If you're on windows and use Docker For Windows then Docker works via VM (MobyLinuxVM). Your volumes (as everting else) are in this VM! It is how to find them:

# get a privileged container with access to Docker daemon
docker run --privileged -it --rm -v /var/run/docker.sock:/var/run/docker.sock -v /usr/bin/docker:/usr/bin/docker alpine sh

# in second power-shell run a container with full root access to MobyLinuxVM
docker run --net=host --ipc=host --uts=host --pid=host -it --security-opt=seccomp=unconfined --privileged --rm -v /:/host alpine /bin/sh

# switch to host FS
chroot /host

# and then go to the volume you asked for
cd /var/lib/docker/volumes/YOUR_VOLUME_NAME/_data
illuminato
  • 1,057
  • 1
  • 11
  • 33
0

If your using windows, your docker files (in this case your volumes) exist on a virtual machine that docker uses for windows either Hyper-V or WSL. However if you need to access those files, you can copy your container files and store them locally on your machine and access the data this way.

docker cp container_Id_Here:/var/lib/mysql path_To_Your_Local_Machine_Here
Monttana16
  • 307
  • 2
  • 9
0

Usually On windows it is located at following path in WSL linux File System.

docker-desktop-data\data\docker\volumes

novice
  • 53
  • 9
0

In windows 11 just copy and paste the following address into File Explorer

\\wsl.localhost\docker-desktop-data\data\docker\volumes\logger_certs\_data

enter image description here