Where is Kubernetes storage location of a Persistent Volume on Docker Desktop for mac? Where is Kubernetes storage location of a Persistent Volume on Docker Desktop for mac? kubernetes kubernetes

Where is Kubernetes storage location of a Persistent Volume on Docker Desktop for mac?


Here how I found it on my Mac:

1. Create PV, PVC, Deployment as you've mentioned. I've just change the PV spec.hostPath.type to DirectoryOrCreate

2. Create a file on the volume using pod shell:

kubeclt exec -ti the-deployment-pod-name-here -- touch /tmp/somefile2.txt

3. Run nsenter pod:

docker run -it --rm --privileged --pid=host alpine:edge nsenter -t 1 -m -u -n -i sh

(on the recent DockerDesktop 3.5.1
screen ~/Library/Containers/com.docker.docker/Data/vms/0/tty
doesn't show me a VM shell prompt any more)

4. Find the file using find in the nsenter container filesystem:

/ # find / -name somefile2.txt/var/lib/mount-docker-cache/entries/docker.tar/a08ee16361132af943875aee79aae165cdbfaf0d203ee97fe9d61d29e307aceb/containers/services/docker/tmp/upper/tmp/netes/somefile2.txt/var/lib/mount-docker-cache/entries/docker.tar/a08ee16361132af943875aee79aae165cdbfaf0d203ee97fe9d61d29e307aceb/containers/services/docker/rootfs/tmp/netes/somefile2.txt/var/lib/mount-docker-cache/entries/services.tar/bbec751ae945082378b0b2d4a7c6e32f9c35164315587914a95acc4bee8df1ff/containers/services/docker/tmp/upper/tmp/netes/somefile2.txt/var/lib/mount-docker-cache/entries/services.tar/bbec751ae945082378b0b2d4a7c6e32f9c35164315587914a95acc4bee8df1ff/containers/services/docker/rootfs/tmp/netes/somefile2.txt/containers/services/docker/tmp/upper/tmp/netes/somefile2.txt/containers/services/docker/rootfs/tmp/netes/somefile2.txt

5. Most promising paths that should work for most cases are:

/containers/services/docker/tmp/upper/containers/services/docker/rootfs+ PV hostPath: /tmp/netes+ filename: somefile2.txt

Note: HostPath PV files are located in DockerVM filesystem. I haven't found a way to share Mac folder to PV in DockerDesktop Kubernetes Pod for now.

Note2: Without specifying StorageClass in PV and PVC, DockerDesktop Kubernetes assigns a default storage class which in my case was hostpath and generates a folder for the PV in the DockerVM temporary location:

/var/lib/k8s-pvs/tmp-storage-claim/pvc-dafbcdf6-a3e8-47cc-af1a-cf740d8ffcd0/somefile2.txt


Based on this article the solution should be as follow:

docker for Mac runs a virtual machine behind the scenes and hides it from you to make things
simpler. Simpler, unless you want to dig deeper. If you want to access persistent volumes created by Docker you need to login into virtual machine first.

  1. We need to "screen into" the Docker driver by executing a command: screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty
  2. You should see a blank screen, just press Enter , and after a while, you should see a command line prompt:
    docker-desktop:~#
  3. Now you're inside Docker's VM and you can cd into volumes dir by typing: cd /var/lib/docker/volumes
  4. Profit, you got there!
  5. If you need to transfer files from your MacOS host into Docker host (for example to put files into docker volumes) use directories shared between host (mac os) and Docker host (Docker VM), you can find a list of such directories under File Sharing tab of your Docker for Mac application.

Note: file sharing is used to share files one way - from host (Mac) to container. You won't see all files stored in persistent volume this way. You will only see the files that you have specially shared with the container. To see the entire persistent volume you need to follow the steps above.

See also: