ConfigFile volumes are used to store configuration files and can inject configuration data into an elastic container instance. This topic describes how to mount a ConfigFile volume to an elastic container instance.
Limits
In a ConfigFile volume, a single configuration file cannot be larger than 32 KB in size, and all configuration files cannot be larger than 60 KB in size.
Configuration description (API mode)
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 | test-volume | The name of volume N. |
Volume.N.Type | String | ConfigFileVolume | Set the value to ConfigFileVolume. This value specifies a ConfigFile volume. |
Volume.N.ConfigFileVolume.ConfigFileToPath.N.Path | String | test/config-test.cnf | The path of the ConfigFile volume relative to the mount directory. |
Volume.N.ConfigFileVolume.ConfigFileToPath.N.Content | String | bGl1bWk= | The Base64-encoded content of the ConfigFile volume. |
Volume.N.ConfigFileVolume.DefaultMode | Integer | 0644 | The default permissions on the ConfigFile volume that are expressed in four-digit octal numbers. For example, 0644 represents the permissions Permission description:
|
Volume.N.ConfigFileVolume.ConfigFileToPath.N.Mode | Integer | 0644 | The permissions on the ConfigFile volume. If you do not specify this parameter, the value of ConfigFileVolume.DefaultMode is used. The permissions are expressed in four-digit octal numbers. For example, 0644 represents the permissions Permission description:
|
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 description (console mode)
When you create an elastic container instance on the Elastic Container Instance buy page, you can specify volumes in the Container Group Configurations section and then mount the volumes to containers in the Container Configurations section.
Specify the volume to be mounted
In the Container Group Configurations section of the Basic Settings step of the Create Container Group wizard, click Advanced Settings.
In the Storage section, click the Configuration Item tab and click Add.
Configure parameters for the ConfigFile volume.
Name: the name of the ConfigFile volume.
Configuration File Path: the relative path of the ConfigFile volume.
Content: the content of the ConfigFile volume. Enter the content in plaintext. The system automatically encodes the content to the Base64 format.
Mount the volume
In the Container Configurations section of the Basic Settings step of the Create Container Group wizard, select a container and click Advanced Settings of the container.
Turn on Storage and click Add.
You can only add the volumes that you specified in the Container Group Configurations section.
If you want to mount volumes to multiple containers, select more containers and repeat the preceding operations.
Configuration example
Call the CreateContainerGroup operation to create an elastic container instance and mount a ConfigFile volume to the instance. The following part shows an example of the parameters. For more information, see CreateContainerGroup.
ContainerGroupName=test-configfile
# Specifies the volume to be mounted.
Volume.1.Name=configfile-demo
Volume.1.Type=HostPathVolume
Volume.1.ConfigFileVolume.ConfigFileToPath.1.Path=test/config-test.cnf
Volume.1.ConfigFileVolume.ConfigFileToPath.1.Content=c2VydmVyLnBvcnQgPSA4MDgw
Volume.1.ConfigFileVolume.DefaultMode=0644
# Mounts 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=configfile-demo
Container.1.VolumeMount.1.MountPath=/data