The location of volumes on Docker Desktop host?

On a Ubuntu host running Docker Desktop, I created a new volume by docker volume create pgadmin4. However, I didn’t find the volume on the host.

Furthermore, the expected directory /var/lib/docker/ doesn’t exist; see more in the screenshot below. I tried listing directory /var/lib/docker/ as the root user, and the result still does not exist, so this doesn’t seem to be a permission issue.

I also checked ps -elf | grep -i "docker", and it seems that the running binary is in the /opt/docker-desktop/ directory; it may be a little different from the docker server. I am tentatively assigning the tag “docker-desktop-for-w”; however, the most precise tag should be “docker-desktop-for-ubuntu”.

I will highly appreciate any hints or suggestions, and please let me know if you need more details.

Screenshot:

work@dockerub:/var/lib$ docker volume inspect pgadmin4
[
    {
        "CreatedAt": "2022-07-27T20:37:43Z",
        "Driver": "local",
        "Labels": {},
        "Mountpoint": "/var/lib/docker/volumes/pgadmin4/_data",
        "Name": "pgadmin4",
        "Options": {},
        "Scope": "local"
    }
]
work@dockerub:/var/lib$ ll /var/lib/docker/volumes/pgadmin4/_data
ls: cannot access '/var/lib/docker/volumes/pgadmin4/_data': No such file or directory
work@dockerub:/var/lib$ sudo su
root@dockerub:/var/lib# ll /var/lib/docker
ls: cannot access '/var/lib/docker': No such file or directory
root@dockerub:/var/lib# ps -elf | grep -i "docker"
4 S avahi        685       1  0  80   0 -  1893 do_pol 09:41 ?        00:00:00 avahi-daemon: running [dockerub.local]
0 S work       17449    1626  0  80   0 - 445334 do_wai 09:51 ?       00:00:18 /opt/docker-desktop/bin/com.docker.backend --with-frontend
0 S work       17461   17449  0  80   0 - 390035 futex_ 09:51 ?       00:00:00 /opt/docker-desktop/bin/com.docker.backend --with-frontend
4 S work       17472   17449  0  80   0 - 5887760 do_pol 09:51 ?      00:00:16 /opt/docker-desktop/Docker Desktop --name=dashboard --enable-crashpad
0 S work       17474   17449  0  80   0 - 344712 futex_ 09:51 ?       00:00:32 vpnkit-bridge --disable wsl2-cross-distro-service,wsl2-bootstrap-expose-ports,transfused --addr tcp+bootstrap+server://0.0.0.0:0/6684d4f98fdf26edd4a03089422eb213580a7b4645490043f26ea93647f6c304 host --control-path fd:3 --bootstrap-host gateway.docker.internal --addr-fd fd:4
0 S work       17476   17449  0  80   0 - 365275 ep_pol 09:51 ?       00:00:18 com.docker.driver.amd64-linux -addr fd:3 -debug
0 S work       17477   17449  0  80   0 - 364754 futex_ 09:51 ?       00:00:01 com.docker.extensions -address extension-manager.sock -watchdog
0 S work       17479   17449  0  80   0 - 327158 futex_ 09:51 ?       00:00:00 com.docker.dev-envs
0 S work       17517   17476  0  80   0 - 383580 futex_ 09:51 ?       00:00:00 /opt/docker-desktop/bin/com.docker.driver.amd64-linux -addr fd:3 -debug
0 S work       17535   17472  0  80   0 - 4251312 do_pol 09:51 ?      00:00:00 /opt/docker-desktop/Docker Desktop --type=zygote --no-zygote-sandbox --enable-crashpad --enable-crashpad
4 S work       17536   17472  0  80   0 - 4251312 do_wai 09:51 ?      00:00:00 /opt/docker-desktop/Docker Desktop --type=zygote --enable-crashpad --enable-crashpad
1 S work       17538   17536  0  80   0 - 4251312 do_pol 09:51 ?      00:00:00 /opt/docker-desktop/Docker Desktop --type=zygote --enable-crashpad --enable-crashpad
4 S work       17546   17476  0  80   0 - 543976 futex_ 09:51 ?       00:00:00 /opt/docker-desktop/bin/virtiofsd --socket-path=virtiofs.sock0 -o cache=auto -o source=/home --sandbox=none --announce-submounts
2 S work       17550   17476  4  80   0 - 1102300 do_pol 09:51 ?      00:15:49 qemu-system-x86_64 -accel kvm -cpu host -machine q35 -m 1987 -smp 2 -kernel /opt/docker-desktop/linuxkit/kernel -append page_poison=1 vsyscall=emulate panic=1 nospec_store_bypass_disable noibrs noibpb no_stf_barrier mitigations=off linuxkit.unified_cgroup_hierarchy=1    vpnkit.connect=tcp+bootstrap+client://gateway.docker.internal:36019/6684d4f98fdf26edd4a03089422eb213580a7b4645490043f26ea93647f6c304 vpnkit.disable=osxfs-data console=ttyS0 -initrd /opt/docker-desktop/linuxkit/initrd.img -serial pipe:/tmp/qemu-console806541486/fifo -drive if=none,file=/home/work/.docker/desktop/vms/0/data/Docker.raw,format=raw,id=hd0 -device virtio-blk-pci,drive=hd0,serial=dummyserial -netdev user,id=net0,ipv6=off,net=192.168.65.0/24,dhcpstart=192.168.65.9 -device virtio-net-pci,netdev=net0 -vga none -nographic -monitor none -object memory-backend-memfd,id=mem,size=1987M,share=on -numa node,memdev=mem -chardev socket,id=char0,path=virtiofs.sock0 -device vhost-user-fs-pci,queue-size=1024,chardev=char0,tag=virtiofs0
1 S work       17581   17535  0  80   0 - 4316305 do_pol 09:51 ?      00:00:19 /opt/docker-desktop/Docker Desktop --type=gpu-process --enable-crashpad --enable-crash-reporter=5a529c55-6917-41e8-afdc-86fe74183e59,no_channel --user-data-dir=/home/work/.config/Docker Desktop --gpu-preferences=UAAAAAAAAAAgAAAIAAAAAAAAAAAAAAAAAABgAAAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAABgAAAAAAAAAGAAAAAAAAAAIAAAAAAAAAAgAAAAAAAAACAAAAAAAAAA= --shared-files --field-trial-handle=0,349030070563931175,14136861513003538376,131072 --disable-features=PlzServiceWorker,SpareRendererForSitePerProcess
0 S work       17590   17472  0  80   0 - 4265691 futex_ 09:51 ?      00:00:00 /opt/docker-desktop/Docker Desktop --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-GB --service-sandbox-type=none --enable-crashpad --enable-crash-reporter=5a529c55-6917-41e8-afdc-86fe74183e59,no_channel --user-data-dir=/home/work/.config/Docker Desktop --shared-files=v8_context_snapshot_data:100 --field-trial-handle=0,349030070563931175,14136861513003538376,131072 --disable-features=PlzServiceWorker,SpareRendererForSitePerProcess --enable-crashpad
1 S work       17592   17581  0  80   0 - 4299200 skb_wa 09:51 ?      00:00:00 /opt/docker-desktop/Docker Desktop --type=broker
0 S root       24686   24678  0  80   0 -  4466 pipe_r 15:31 pts/2    00:00:00 grep --color=auto -i docker
root@dockerub:/var/lib# ll /var/lib/docker
ls: cannot access '/var/lib/docker': No such file or directory
root@dockerub:/var/lib# 

This is because Docker Desktop is not just a Graphical interface. It creates a virtual machine and runs Docker inside that virtual machine. You will not find volumes on your host and you will not be able to access the container IP addresses directly.

You can find here how Docker Desktop runs the VM on Linux (Qemu KVM) and why it does that:

If you want to get into the VM, you could probably use this solution from Justin Cormack:

And a useful gist from Bret Fisher: Getting a Shell in the Docker Desktop Mac VM · GitHub

It is about Mac, but the nsenter container works the same way. If you need the filesystem, then mount the host filesystem of the VM:

docker run -it --rm --privileged --pid=host -v /:/hostfs justincormack/nsenter1

But I am not sure if it works on Linux and it doesn’t mount the filesystem of Ubuntu.

So when you work with Docker Desktop on any system, you need to think of Docker as if it were on a remote machine that you don’t have access to. You can only use the docker command to forward ports, or copy in or out files even from volumes.

I have some old scripts here you could probably use to copy out volume contents if it is not too large:

I am using WSL 2 based engine. I can paste

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

into File Explorer, and then drill down to “volumes” where I can find my named volume there.

– It works for me, I am not sure if it works elsewhere…

I have done a blog on it:

Python: Docker volumes – where is my SQLite database file?

1 Like

We discussed it in an other topic with @meyay, but that didn’t work for me. Your solution worked. I don’t use Docker on Windows a lot, but I definitely thank you for sharing your way.

Hi, @behai, Thank you for sharing your tips about Docker Desktop for Windows. However, as the original post says

… , the most precise tag should be “docker-desktop-for-ubuntu”. …

It’s just that our forum doesn’t have the tag available yet. And we are still looking forward to inputs about Docker Desktop for Ubuntu (or for Linux).

Oh, right… I forgot that. Since we already have some new categories, I will ask to give this a higher priority.

As others have mentioned, docker desktop for linux runs inside a VM, therefore it does not store it’s contents on the host machine, but rather inside a .raw disk file. See Where does Docker Desktop store Linux containers?

Here is how I was able to access the disk contents:

  1. Find the Docker.raw file and run the following command

    • ➜ sudo fdisk -lu /path/to/Docker.raw
      Disk Docker.raw: 64 GiB, 68719476736 bytes, 134217728 sectors
      Units: sectors of 1 * 512 = 512 bytes
      Sector size (logical/physical): 512 bytes / 512 bytes
      I/O size (minimum/optimal): 512 bytes / 512 bytes
      Disklabel type: dos
      Disk identifier: 0xf1a3943b
      
      Device      Boot Start       End   Sectors Size Id Type
      Docker.raw1       2048 134217727 134215680  64G 83 Linux
      
      As you can see from the output the disk is divided into sectors of 512 bytes, with the one and only partition starting at offset 2048. Now we can use this information to mount the partition.
  2. Mount the data partition using the mount command while specifying an offset. The partition offset is calculated by multiplying the sector size with the start offset. In my case, 512 x 2048 = 1048576

    • ➜ sudo mount -o offset=1048576 /path/to/Docker.raw /path/to/mount/target/
      
      ➜ ls -al /path/to/mount/target/
      total 2097216
      drwxr-xr-x  11 root       root             4096 Jan 25 11:24 .
      drwxr-xr-x 171 root       root             4096 Jan 25 16:07 ..
      drwxr-xr-x   3 root       root             4096 Jan 25 11:24 cni
      drwx--x--x  10 root       root             4096 Jan 25 11:24 containerd
      drwx--x--x   3 root       root             4096 Jan 25 11:24 desktop-containerd
      drwx--x---  13 root       root             4096 Jan 25 11:27 docker
      drwxr-xr-x   2 root       root             4096 Jan 25 11:24 kubeadm
      drwxr-xr-x   2 root       root             4096 Jan 25 11:24 kubelet-plugins
      drwx------   2 root       root            16384 Jan 25 11:24 lost+found
      -rw-r--r--   1 root       root               37 Jan 25 11:24 machine-id
      drwxr-xr-x   3 root       root             4096 Jan 25 11:27 mount-services-cache
      drwxr-xr-x   4 root       root             4096 Jan 25 11:24 nfs
      -rw-------   1 root       root       2147483648 Jan 25 11:27 swap
      

From the above output, you can see the docker folder which is where you will find all volume data. If you want to make the folder writable, prepend ,rw after the offset option.

Source(s):

1 Like