All Products
Search
Document Center

Elastic Container Instance:Configure startup commands and arguments for a container

更新時間:Dec 26, 2023

Elastic Container Instance starts a container by using predefined arguments in the container image. If you did not configure startup commands or arguments when you created an image or if you want to modify them, you can configure the commands or arguments when you create an elastic container instance. This topic describes how to configure the commands and arguments that are run after a container is started.

Features

If you want to override the default startup settings of an image, such as the working directory and startup commands and arguments, you can set the following fields in the configuration file of an elastic container instance:

  • WorkingDir

    When you create an image, you can set the WORKDIR field to specify the working directory of a container. The startup commands of the container are run in the specified directory. For more information, see WORKDIR.

    You can override the WORKDIR value provided by the image by setting the WorkingDir field in the configuration file of an elastic container instance.  

    Note

    • If the WORKDIR field is not specified in the image and the WorkingDir field is not specified in the elastic container instance, the working directory is set to the root directory.

    • If the specified working directory does not exist, the system creates the directory.

  • Command and Arg

    When you create an image, you can set the CMD and ENTRYPOINT fields to specify the commands and arguments that are run after the container is started. For more information, see ENTRYPOINT and CMD.

    You can override the CMD and ENTRYPOINT values provided by the image by setting the Command and Arg fields in the configuration file of an elastic container instance. The following table describes the validity rules.

    ENTRYPOINT value

    CMD value

    Command value

    Arg value

    Command that is run

    Description

    [mkdir]

    [/data/backup]

    Not specified

    Not specified

    [mkdir /data/backup]

    None of Command and Arg is specified. The commands and arguments specified by CMD and ENTRYPOINT are run.

    [mkdir]

    [/data/backup]

    [cd]

    Not specified

    [cd]

    Command is specified but Arg is not. Only commands specified by Command are run, and ENTRYPOINT and CMD are ignored.

    [mkdir]

    [/data/backup]

    Not specified

    [/opt/backup]

    [mkdir /opt/backup]

    Arg is specified but Command is not. The commands and arguments specified by Arg and ENTRYPOINT are run.

    [mkdir]

    [/data/backup]

    [cd]

    [/opt/backup]

    [cd /opt/backup]

    Both Command and Arg are specified, and the commands and arguments specified by Command and Arg are run.

    Important

    The values of Command and Arg must be supported by the container image. Otherwise, the container fails to start.

Configurations

API mode

When you call the CreateContainerGroup operation to create an elastic container instance, you can use the WorkingDir parameter to specify the working directory. You can also use the Command and Arg parameters to specify the startup commands and arguments. The following table describes the parameters for the CreateContainerGroup operation. For more information, see CreateContainerGroup.

Parameter

Type

Example

Description

Container.N.WorkingDir

string

/usr/local/

The working directory of container N.

Container.N.Command.N

array

sleep

Command N that you want to run to start container N. You can specify up to 20 commands.

Container.N.Arg.N

array

100

Argument N that is passed to the startup command of container N. You can specify up to 10 arguments.

Console mode

When you create an elastic container instance on the Elastic Container Instance buy page, you can configure startup commands and arguments for containers by setting parameters in the Container Configurations section.

Startup command of containers