Disks are block storage products provided by Alibaba Cloud that feature low latency, high performance, durability, and high reliability. You can use the FlexVolume plug-in to mount disks to an elastic container instance as volumes. This topic describes how to mount a disk as a volume on an elastic container instance.
Limitations
Only pay-as-you-go disks can be mounted. For more information, see Block storage billing.
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.
A disk can only be mounted to an instance in the same availability zone. Cross-zone mounting is not supported.
You cannot mount NVMe disks that have the multi-mount feature enabled (also known as NVMe shared disks).
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 relevant parameters are described below. For more information, see CreateContainerGroup.
Declare a volume
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 path within the container at which to mount the volume. Data in this directory is obscured by the data on the volume. |
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
The following examples show the parameters used when you call the CreateContainerGroup operation to create an elastic container instance and mount a disk as a volume. For more information, see CreateContainerGroup.
Example 1: Statically mount 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=/dataNoteWhen you statically mount an existing disk, it must be in the Pending state and in the same availability 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