Suppose I use a Cloud SDK Docker container, which lets me run various gcloud
commands, including gcloud compute disks create
which creates a Google persistent disk. However I cannot then attach to this disk within the container, since gcloud compute instances attach-disk
only works on GCE instances and not Docker containers.
Is there a way for the container to attach or even access the persistent disk? Can I in fact attach persistent disks to arbitrary Linux machines, not just GCE instances?
I know I can use either Docker or Kubernetes to attach persistent disks fixed and determined before the container is launched, but what I need is the container itself to attach to arbitrary persistent disks as determined by container code.
Can I in fact attach persistent disks to arbitrary Linux machines, not just GCE instances?
No, you can only attach GCE persistent disks to GCE VMs.
I cannot then attach to this disk within the container, since gcloud compute instances attach-disk only works on GCE instances and not Docker containers.
If the container is running inside a GCE VM, you should be able to attach the persistent disk to the VM that hosts the container.
I need is the container itself to attach to arbitrary persistent disks as determined by container code.
If you run your container in privileged mode, then you should be able to run the appropriate mount commands to mount the disk after you've attached it to the VM. You can try mapping in a volume to the container that is initially empty and then mounting the PD to that path, but I'm not sure whether it will work.