edit-icon download-icon

Implement multiple environments by using configurations

Last Updated: Feb 14, 2018

An application consists of codes and configurations. After an application is containerized, the configurations are usually transmitted by using container environment variables to deploy multiple applications using the same image and different configurations.

Swarm mode supports the orchestration syntax of Compose V1/V2 and Compose V3. For the environment variable syntax of Compose V3, see Environment variable.

Limits

  • When associating a configuration file with an application, make sure the configuration file is in the same region as the application.
  • Currently, associating a configuration file when creating an application is only available when you create the application by using an orchestration template.

Scenarios

Create an application

  1. Log on to the Container Service console.

  2. Click Configurations under Swarm in the left-side navigation pane.

  3. Select the region in which you want to create a configuration from the Region list and click Create.

    1

  4. Enter the configuration file information and click OK.

    • File Name: It can contain 1–32 characters.
    • Description: It can contain up to 128 characters.
    • Configuration: You can add up to 50 configurations in a region. Enter the Variable Name and Variable Value, and then click Add on the right. In this example, enter size as the variable name and 3 as the variable value. The following orchestration template will reference this variable as the parameter of container quantity, indicating to start three containers when you create an application for the first time.

    1

    You can also click Edit JSON File. The JSON Format dialog box appears. Enter the configurations in the dialog box and click OK.

    1

  5. Click Applications in the left-side navigation pane.

  6. Select the cluster in the same region as the created configuration from the Cluster list and click Create Application.

  7. Complete the basic information for the application and click Create with Orchestration Template.

    Note: The cluster on which the application will be deployed and the created configuration must be in the same region.

  8. Enter the following orchestration template and then click Create and Deploy.

    Compose V1/V2 orchestration example:

    Wherein, size is a dynamic variable and will be overwritten by the value in the configuration.

    1. web:
    2. image: wordpress:4
    3. ports:
    4. - 80
    5. restart: always
    6. labels:
    7. aliyun.logs: /var/log
    8. aliyun.probe.url: http://container/license.txt
    9. aliyun.probe.initial_delay_seconds: '10'
    10. aliyun.routing.port_80: http://wordpress
    11. aliyun.scale: $size #Note

    Compose V3 orchestration example:

    Wherein, size is a dynamic variable and will be overwritten by the value in the configuration.

    1. version: '3'
    2. services:
    3. web:
    4. image: wordpress:4
    5. ports:
    6. - 80
    7. deploy:
    8. replicas: $size #Note
    9. restart_policy:
    10. condition: on-failure
  9. The Template Parameter dialog box appears. Select the configuration file to be associated with from the Associated Configuration File list.

  10. Click Replace Variable and click OK.

    1

Update an application

If you associated a configuration file when creating an application, you can update the application by modifying the configuration file and redeploying the application.

  1. Log on to the Container Service console.

  2. Click Configurations under Swarm in the left-side navigation pane.

  3. Select the region in which the configuration you want to modify resides from the Region list, and click Modify at the right of the configuration.

    1

  4. Click Confirm in the displayed dialog box.

    1

  5. Click Edit (changes to Save after you click it) at the right of the variable you want to modify. Modify the variable value. Click Save and then click OK.

    1

  6. Click Applications in the left-side navigation pane.

  7. Select the cluster in the same region as the configuration, and then click Redeploy at the right of the application.

    1

    Before the update, the number of containers in the container list is three.

    1

    After the update, the number of containers is changed to two.

    1

Trigger an update

If you associated a configuration file when creating an application, you can redeploy the application by using the redeployment trigger.

  1. Log on to the Container Service console.

  2. Click Configurations under Swarm in the left-side navigation pane.

  3. Select the region in which the configuration you want to modify resides from the Region list, and click Modify at the right of the configuration.

    1

  4. Click Confirm in the displayed dialog box.

    1

  5. Click Edit (changes to Save after you click it) at the right of the variable you want to modify. Modify the variable value. Click Save and then click OK.

    1

  6. Create a redeployment trigger.

    For how to create a trigger, see Triggers.

    1

  7. Trigger the redeployment trigger.

    1. curl "https://cs.console.aliyun.com/hook/trigger?triggerUrl=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Thank you! We've received your feedback.