All Products
Search
Document Center

Elastic Container Instance:Mount a ConfigFile volume

Last Updated:Oct 10, 2023

A ConfigFile volume is a configuration file that is used to inject configuration data into an elastic container instance. This topic describes how to mount a ConfigFile volume to an elastic container instance.

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 -rw-r--r--. 0 corresponds to-, indicating that the file type is regular file. 644 corresponds to the subsequent nine characters. rw- represents user permissions. r-- represents user group permissions. r-- represents other user permissions.

Permission description:

  • ---: no permissions. The octal value is 0.

  • --x: only the execute permissions. The octal value is 1.

  • -w-: only the write permissions. The octal value is 2.

  • -wx: the write and execute permissions. The octal value is 3.

  • r--: only the read permission. The octal value is 4.

  • r-x: the read and execute permissions. The octal value is 5.

  • rw-: the read and write permissions. The octal value is 6.

  • rwx: the read, write, and execute permissions. The octal value is 7.

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 -rw-r--r--. 0 corresponds to-, indicating that the file type is regular file. 644 corresponds to the subsequent nine characters. rw- represents user permissions. r-- represents user group permissions. r-- represents other user permissions.

Permission description:

  • ---: no permissions. The octal value is 0.

  • --x: only the execute permissions. The octal value is 1.

  • -w-: only the write permissions. The octal value is 2.

  • -wx: the write and execute permissions. The octal value is 3.

  • r--: only the read permission. The octal value is 4.

  • r-x: the read and execute permissions. The octal value is 5.

  • rw-: the read and write permissions. The octal value is 6.

  • rwx: the read, write, and execute permissions. The octal value is 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 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:

  • 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 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

  1. In the Container Group Configurations section of the Basic Settings step of the Create Container Group wizard, click Advanced Settings.

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

  3. 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.

    Configuration item

Mount the volume

  1. 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.

  2. Turn on Storage and click Add.

    You can only add the volumes that you specified in the Container Group Configurations section.

    Configuration item - 2
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 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=bGl1bWk=
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