A docker image running on my laptop with docker volume folder myVolume inside it bounded to a folder on my desktop ( can be any directory on host machine) Desktop-Volume :

docker run -it -v ~/Desktop/Desktop-Volume:/myVolume ..

There are files and folders inside Desktop-Volume , when the docker app runs this folder got populated with newly created files which of course after shutting down the docker they still remain in Desktop-Volume ,

Now, i create a Kubernetes cluster on Google Cloud and make PersistentVolumes and run the deployment , but the container crashes because it depends on those pre-processed Desktop-Volume in order to initialize , so i need to place those files into PersistentVolumes before running my container on Kubernetes cluster ,but i don't know how .

The pod was something like this

        - name: demo
            claimName: disk
        - name: myContainer
          image: "gcr.io/my-instance/myDocker:latest"

            - mountPath: "/myVolume"
              name: disk

I also tried :


i connect to cluster shell and from there upload the Desktop-Volume.zip from my laptop to the shell then unzip and set

    path: "/home/<name>/Desktop-Volume"

but the container crashed no such a file or directory referring to files which reside in myVolume through Desktop-Volume

  1. how can i place the content of my pre-processedDesktop-Volume files into PersistentVolumes before running container on cluster ?
  2. where is the mount path of the PersistentVolumes so that i can ls to there and see my files ?
  • if you have a pod mounting a volume and this you want to download data from s3, you can create a sidecar container to do this job – c4f4t0r Aug 21 '19 at 10:31
  • You need to create a new disk on GCE, make sure it is prepopulated and then ensure you PV uses that pre existing disk instead allowing the disk to be created dynamically. I'll provide an answer with more details shortly – Patrick W Sep 13 '19 at 13:17

This sounds like your container needs a pre-populated volume to start up. You could use hostPath like you mentioned but this is not recommended for a couple reasons. Instead, you'll transfer your data to a GCE PD, make sure your PV uses that pre-existing disk and then mount that to your pod. Here's some details:

1. Copy data to a GCE PD: Spin up a VM then either transfer your data from your local machine to the VM or create the filesystem and prep the files required directly from the VM instead of your local machine.

2. Prep a GCE disk for PV use: Either detach the GCE disk from your VM or take a snapshot of the disk and create a new GCE PD from the snapshot.

3. Create a PV to consume the disk: It is important to follow the documentation for this step carefully. The default behavior of PVC in GKE is to be provisioned dynamically using a StorageClass. Instead, we want to make sure the PV is created first and targets the GCE-PD explicitely. GCP has a good walk through on how to do this.

4. Create the PVC to target the PV: As I mentioned, the default behavior will be to create a brand new disk dynamically which will be a blank new disk. Make sure to follow the walk through carefully. If any of the fields are set incorrectly, a different PV will be created.

5. Mount the PVC in your pod: First of all note that GCE disks don't support read/write many, so this PVC can only be used by a single pod.

If you need to have more than a single pod, you'll need create multiple PVCs using the above steps. If the files and filesystem the container needs only has to be read only, then you have two other options to make it easier:

  1. Create the GCE disk in readOnlyMnay mode, this way the same PVC can be used across multiple pods.

  2. Use a configMap with all the files you need. This takes a little bit more planning before hand to make sure all the appropriate files are in the right place

| improve this answer | |

If I understand your questions you want a PersistentVolume that behaves the way like your local folder on your Desktop when it's used as Volume on your local docker deployment.

The PersistentVolume is backed by Compute Engine persistent disks, that means in order to access to the disk you need to attache it to a VM for use it, like this.

I think you need a solution more flexible than PersistentVolumnes on GKE, because the different mounting points you want to use (your local Desktop and kubernets).

You can use Cloud Storage FUSE, this adapter allows you mount a Cloud Storage buckets as a filesystem, you can mount it on your desktop, another VM and kubernetes.

Another option it's Vault.


| improve this answer | |
  • I edited the problem for clarification . the Desktop-Volume is just an example . In general ; how to place files to PersistentVolumnes before running a container and get access to PersistentVolumnes files – Fizmath Aug 21 '19 at 7:58
  • I still think you need another solution, more flexible than a PersistentVolume. The PersistentVolume it's a GCE persistant disk and kubernetes will manage this if you want to use it on GKE. Check the documentation here mention options like NFS. Also check kubernetes persistent-volumes – DavidC Aug 21 '19 at 17:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.