Mount a ConfigFile volume for an ECI instance

更新时间:
复制 MD 格式

A ConfigFile volume is a type of volume that stores configuration files, allowing you to inject configuration data into an Elastic Container Instance (ECI) instance. This topic describes how to mount a ConfigFile volume for an ECI instance.

Limits

In a ConfigFile volume, a single configuration file cannot exceed 32 KB in size, and the total size of all configuration files cannot exceed 60 KB.

Configuration (API)

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

test-volume

The name of the volume.

Volume.N.Type

String

ConfigFileVolume

Set the value to ConfigFileVolume to declare a ConfigFile volume.

Volume.N.ConfigFileVolume.ConfigFileToPath.N.Path

String

test/config-test.cnf

The path of the configuration file, relative to the mount directory.

Volume.N.ConfigFileVolume.ConfigFileToPath.N.Content

String

bGl1bWk=

The Base64-encoded content of the configuration file.

Volume.N.ConfigFileVolume.DefaultMode

Integer

0644

The default permissions for the configuration files, specified as a four-digit octal number.

For example, 0644 maps to -rw-r--r--. The leading 0 maps to - and indicates a regular file. The remaining three digits (644) map to the next nine characters and represent three permission sets: the user has rw- permissions, the group has r-- permissions, and others have r-- permissions.

The permissions are described as follows:

  • ---: no permissions (octal value 0).

  • --x: execute only (octal value 1).

  • -w-: write only (octal value 2).

  • -wx: write and execute (octal value 3).

  • r--: read only (octal value 4).

  • r-x: read and execute (octal value 5).

  • rw-: read and write (octal value 6).

  • rwx: read, write, and execute (octal value 7).

Volume.N.ConfigFileVolume.ConfigFileToPath.N.Mode

Integer

0644

The permissions for the configuration file, specified as a four-digit octal number. If this parameter is omitted, the value of ConfigFileVolume.DefaultMode is used.

For example, 0644 maps to -rw-r--r--. The leading 0 maps to - and indicates a regular file. The remaining three digits (644) map to the next nine characters and represent three permission sets: the user has rw- permissions, the group has r-- permissions, and others have r-- permissions.

The permissions are described as follows:

  • ---: no permissions (octal value 0).

  • --x: execute only (octal value 1).

  • -w-: write only (octal value 2).

  • -wx: write and execute (octal value 3).

  • r--: read only (octal value 4).

  • r-x: read and execute (octal value 5).

  • rw-: read and write (octal value 6).

  • rwx: read, write, and execute (octal value 7).

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:

  • None: The volume mount does not receive subsequent mounts that are mounted to this volume or its subdirectories.

  • HostToContainer: The volume mount receives all subsequent mounts that are mounted to this volume or its subdirectories.

  • Bidirectional: This value has a similar effect as HostToContainer. The volume mount receives all subsequent mounts that are mounted to this volume or its subdirectories. In addition, all volume mounts created by container N are propagated back to the host and to all containers of all elastic container instances that use the same volume.

Default value: None.

Note

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 (console)

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.

Declare a volume

  1. In the Container Group Configurations section, expand Advanced Settings.

  2. In Storage, select the Configuration Item tab and click Add.

  3. Configure the parameters for the ConfigFile volume.

    • Name: The name of the ConfigFile volume.

    • Configuration File Path: The path of the configuration file relative to the mount directory.

    • Content: Enter the plaintext content of the configuration file. The console automatically Base64-encodes it.

Mount the volume

  1. In the Container Configurations section, select a container and expand its Advanced Settings.

  2. Turn on Storage and click Add.

    Only volumes that you declared in the Container Group Configurations section are available to be mounted.

    Select the configfile-demo volume of type Configuration Item, set the mount path in the container to /data, and do not select the Read-only option.

Note

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 ECI instance and mount a ConfigFile volume to it. The following example shows the required request parameters. For more information, see CreateContainerGroup.

ContainerGroupName=test-configfile
#Declare a volume
Volume.1.Name=configfile-demo
Volume.1.Type=ConfigFileVolume
Volume.1.ConfigFileVolume.ConfigFileToPath.1.Path=test/config-test.cnf
Volume.1.ConfigFileVolume.ConfigFileToPath.1.Content=c2VydmVyLnBvcnQgPSA4MDgw
Volume.1.ConfigFileVolume.DefaultMode=0644
#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=configfile-demo
Container.1.VolumeMount.1.MountPath=/data