All Products
Search
Document Center

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

Last Updated:Aug 26, 2024

Elastic Container Instance starts a container based on the 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 the startup commands or arguments configured in the image, you can configure the commands or arguments when you create an elastic container instance. The startup commands and arguments of a container define the startup behaviors and initialization process of the container and ensure that the container can run as expected and provide required services. This topic describes how to configure startup commands and arguments for a container.

Feature description

If you want to override the default startup settings of an image, such as the working directory and the startup commands and arguments, you can configure the following parameters:

  • WorkingDir

    When you create an image, you can configure the WORKDIR parameter 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.

    When you create an elastic container instance, you can configure the WorkingDir parameter of containers to override the WORKDIR value provided by the image.  

    Note
    • If the WORKDIR parameter is not configured in the image and the WorkingDir parameter is not configured 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 configure the CMD and ENTRYPOINT parameters to specify the commands and arguments that are run after the container is started. For more information, see ENTRYPOINT and CMD.

    When you create an elastic container instance, you can configure the Command and Arg parameters of containers to override the CMD and ENTRYPOINT values provided by the image. The following table describes the validity rules.

    Important

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

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

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

Configuration description

OpenAPI

When you call the CreateContainerGroup operation to create an elastic container instance, you can use the WorkingDir parameter to specify the working directory and use the Command and Arg parameters to specify the startup commands and arguments. The following table describes the parameters of 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

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

容器启动命令