Reputation: 1196
So I am using this gcloud console command to create an instance from container image
gcloud compute instances create-with-container test-instance \
--zone us-xx \
--container-image asia.gcr.io/my-project/my-docker-image \
--container-privileged \
--network my-network \
--subnet my-net-sub \
--create-disk name=test-data,device-name=test-data,auto-delete=yes,size=200GB,type=pd-ssd \
--container-mount-disk name=test-data,mount-path=/mnt/disks/data \
--service-account [email protected]
which works fine and creates the instance, but it does not mount the data-disk. why? more precisely, to add the data disk I need to
How can I specify the create partition with ext4 and then mount the partition part?
Upvotes: 0
Views: 2068
Reputation: 4443
You can't mount the host's disk to the container (use the same disk in both). You can however mount a directory or another disk. Either way you will be able to store data on it and both OS'es (host & container) will be able to read/write from it.
Let's say you want to store all data in the host OS disk in /datadir/
and you want it to be mounted inside the container under /mnt/disks/data
. Below you will find a complete (and tested) example to use:
gcloud compute instances create-with-container mytestvm1 \
--zone=europe-west3-c \
--container-image=gcr.io/google-containers/mycontainer \
--container-privileged \
--network default \
--subnet default \
--create-disk name=test-data,device-name=test-data,auto-delete=yes,size=20GB,type=pd-ssd \
--container-mount-host-path=mount-path=/mnt/disks/data,host-path=/home/myhomedir/,mode=rw \
--service-account=my_service_account@developer.gserviceaccount.com
If you need another disk mounted then just change the line:
--container-mount-host-path=mount-path=/mnt/disks/data,host-path=/home/myhomedir/,mode=rw \
to
--container-mount-disk=mount-path=/mnt/disks/data,name=data1,mode=rw \
Upvotes: 6