Disks are block-level storage products provided by Alibaba Cloud. Disks feature low latency, high performance, high durability, and high reliability. You can use the FlexVolume plug-in to mount disks to elastic container instance as volumes. This topic describes how to mount a disk volume to an elastic container instance.
Precautions
Only pay-as-you-go disks can be mounted. For more information, see EBS devices.
Disks cannot be shared. A disk can be mounted to only one instance.
A maximum of six disk volumes can be mounted to an elastic container instance.
The instance to which a disk is mounted must reside in the same zone as the disk.
NVMe disks, for which the multi-mount feature is enabled, cannot be mounted to elastic container instances.
You cannot mount a disk that has partitions.
Configuration description
When you call the CreateContainerGroup API operation to create an elastic container instance, you can use Volume-related parameters to specify volumes, and then use Container.VolumeMount-related parameters to mount the volumes to containers. The following part describes the relevant parameters. For more information, see CreateContainerGroup.
Specify the volume to be mounted
When you use Volume-related parameters to specify volumes, you must first specify the types and names of the volumes. Then, you must configure other Volume-related parameters based on the value of the Volume.N.Type parameter.
Parameter | Type | Example | Description |
Volume.N.Name | String | disk-demo | The name of the volume N. |
Volume.N.Type | String | FlexVolume | Set the value to FlexVolume. The value specifies a volume that is mounted by using the FlexVolume plug-in. |
Volume.N.FlexVolume.Driver | String | alicloud/disk | The driver type when you use the FlexVolume plug-in to mount a volume. Set the value to |
Volume.N.FlexVolume.FsType | String | ext4 | The type of the file system. Select the file system type of the disk. Valid values: ext4, ext3, xfs, and vfat. Default value: ext4. |
Volume.N.FlexVolume.Options | String | {"volumeSize":"50","tags":"test:eci"} | The options when you set the Volume.N.Type parameter to FlexVolume. Each option is a key-value pair in the JSON string. When you use the FlexVolume plug-in to mount a disk, this parameter represents the configuration parameters of the disk volume. The following parameters can be configured: Important If you do not specify the volumeId parameter, you must specify the volumeSize parameter. If you specify the volumeId parameter, the values of the attribute parameters of the disk, such as volumeSize, are ignored.
|
Mount volumes
After you specify volumes, you can use VolumeMount-related parameters to mount the volumes to containers.
Parameter | Type | Example | Description |
Container.N.VolumeMount.N.Name | String | test-volume | The name of volume N to be mounted to container N. This value is the value of Volume.N.Name. |
Container.N.VolumeMount.N.MountPath | String | /usr/share | The directory to which volume N is mounted. Data under this directory is overwritten by the data on the volume. Make sure that this value is correct. |
Container.N.VolumeMount.N.SubPath | String | /usr/sub | The subdirectory of the volume. This parameter specifies different subdirectories of the same volume that the instance can mount to different subdirectories of containers. |
Container.N.VolumeMount.N.ReadOnly | Boolean | false | Specifies whether the mount directory is read-only. Default value: false. |
Container.N.VolumeMount.N.MountPropagation | String | None | The mount propagation setting of volume N. Mount propagation allows you to share volumes that are mounted to one container to other containers in the same elastic container instance, or even to other elastic container instances on the same host. Valid values:
Default value: None. |
Volumes can also be mounted to init containers. The required parameters are similar to the parameters in the preceding table. You only need to change Container to InitContainer.
Configuration examples
Call the CreateContainerGroup API operation to create an elastic container instance and mount a disk to the instance as a volume. The following part describes the parameters. For more information, see CreateContainerGroup.
Example 1: (Statically) Specify an existing disk
ContainerGroupName=test-disk1 SecurityGroupId=sg-bp1daxpbz9lzpvvc**** VSwitchId=vsw-bp1gds63lmlm7ib05**** # Specify the volume to be mounted. Volume.1.Name=disk-demo Volume.1.Type=FlexVolume Volume.1.FlexVolume.Driver=alicloud/disk Volume.1.FlexVolume.FsType=ext4 Volume.1.FlexVolume.Options={"volumeId":"d-2zebuamrpar7xnj****"} # Mount the volume to a container. Container.1.Name=nginx Container.1.Image=registry-vpc.cn-hangzhou.aliyuncs.com/eci_open/nginx:1.14.2 Container.1.VolumeMount.1.Name=disk-demo Container.1.VolumeMount.1.MountPath=/data
NoteWhen you statically specify an existing disk, the specified disk must be in the Pending state and reside in the same zone as the elastic container instance.
Example 2: (Dynamically) Create a new disk
ContainerGroupName=test-disk2 # Specify the volume to be mounted. Volume.1.Name=disk-demo Volume.1.Type=FlexVolume Volume.1.FlexVolume.Driver=alicloud/disk Volume.1.FlexVolume.FsType=ext4 Volume.1.FlexVolume.Options={"volumeSize":"50","tags":"test:eci"} # Mount the volume to a container. Container.1.Name=nginx Container.1.Image=registry-vpc.cn-hangzhou.aliyuncs.com/eci_open/nginx:1.14.2 Container.1.VolumeMount.1.Name=disk-demo Container.1.VolumeMount.1.MountPath=/data