The Image Builder feature customizes image content by using image templates. You can specify image components or directly specify commands to create an image template. An image component is composed of one or more commands. Command is the minimum unit of an image template. This topic provides the syntax and examples of the common commands supported by Image Builder.
Command syntax
Image Builder supports commands in the YAML Ain't Markup Language (YAML) format for Linux and Windows operating systems and commands in the DockerFile format only for Linux operating systems.
Commands in the DockerFile format are not flexible enough and have operating system restrictions. We recommend that you use the YAML format.
Commands in the YAML and DockerFile formats have the following syntax requirements:
YAML: You must define the
Parameters
andTasks
fields. Syntax:Parameters: # (Optional) Define custom parameters. param1: # (Required) Specify the parameter name. Type: String # (Required) Specify the parameter type. Valid values: String, Number, and Boolean. DefaultValue: defaultValue # (Optional) Configure the default value of the parameter. If a parameter does not have a default value, you must explicitly pass in the parameter to the image template that contains the image component in which the parameter is included. Tasks: # Define the task list of the image component, which contains at least one task. The tasks in the task list are executed in sequence. - Name: taskName1 # (Required) Specify the task name. Action: RunShellCommand # (Required) Specify the task action. For more information, see the component commands in the YAML format. Properties: # Specify action properties. The properties vary based on the action. commandContent: echo {{ param1 }} # Reference a custom parameter. - Name: taskName2 Action: action2 Properties: action2Property1: {{ taskName1.stdout }} # Reference the output of the taskName1 task.
NoteYou can reference the preceding parameters as properties in the Tasks field. The following sample code provides the reference syntax:
{{taskName1.stdout}}
DockerFile
Each line contains only one command or part of one command.
One command can be split into multiple lines. An escape character (\) must be added to the end of each line except for the last line.
Commands supported by Image Builder
The following section describes the command syntax supported by image components when you use Image Builder to create image components in the Elastic Compute Service (ECS) console and by calling API operations.
Component commands supported by the ECS console and API operations
(Recommended) YAML format
Command | Syntax or example | Description | Output |
RunShellCommand |
|
|
|
RunPowerShellCommand |
|
| |
InvokeCommand |
| This command is used to run a common command. | |
OSSDownload |
|
| None. |
OSSUpload |
|
| |
WebDownload |
| This command is used to download a file from the network. | |
Reboot |
| This command is used to restart an ECS instance. |
DockerFile format
Command | Syntax or example | Description |
RESTART |
|
|
RUN |
|
|
ENV |
|
Note Double quotation marks (") are required before and after the value of each system variable in the command. Example: |
WORKDIR |
| This command is used to specify a working directory. |
COPY |
| This command is used to copy files. Note Network files must be downloaded by using the |
USER |
| This command is used to specify the username of the account that is used to run commands. Note Replace the |
LABEL |
|
|
CMD |
| This command is used to enable specific commands and parameters to run on system startup. |
ENTRYPOINT |
| This command is used to enable specific commands and parameters to run on system startup. Note
|
Template commands in the DockerFile format (supported only by API operations)
Command | Syntax or example | Description |
COMPONENT |
| This command is used to specify image components. You can specify system components or custom components.
|
RESTART |
|
|
RUN |
|
|
ENV |
|
Note Double quotation marks (") are required before and after the value of each system variable in the command. Example: |
WORKDIR |
|
|
COPY |
|
Note Network files must be downloaded by using the |
USER |
|
Note Replace the |
LABEL |
|
|
CMD |
|
|
ENTRYPOINT |
|
Note
|
Examples of component commands
When you create an image component, you can select Build or Test. You can copy the following sample template commands and modify the commands based on your business scenario.
A build component is used to customize image content and can be used only in image build templates.
A test component is used to test whether an image can run as expected and can be used only in image test templates.
Build component
Linux operating system
Parameters:
message:
Type: String
DefaultValue: hello world
Tasks:
- Name: HelloWorld
Action: RunShellCommand
Properties:
commandContent: echo {{messgae}}
- Name: HelloWorldAgain
Action: RunShellCommand
Properties:
commandContent: echo {{HelloWorld.stdout}}
Windows operating system
Parameters:
message:
Type: String
DefaultValue: hello world
Tasks:
- Name: HelloWorld
Action: RunPowerShellCommand
Properties:
commandContent: echo {{messgae}}
- Name: HelloWorldAgain
Action: RunPowerShellCommand
Properties:
commandContent: echo {{HelloWorld.stdout}}
Test component
Linux operating system
Parameters:
message:
Type: String
DefaultValue: hello world
Tasks:
- Name: HelloWorld
Action: RunShellCommand
Properties:
commandContent: echo {{messgae}}
- Name: HelloWorldAgain
Action: RunShellCommand
Properties:
commandContent: |-
echo {{HelloWorld.stdout}}
exit 0
Windows operating system
Parameters:
message:
Type: String
DefaultValue: hello world
Tasks:
- Name: HelloWorld
Action: RunPowerShellCommand
Properties:
commandContent: echo {{messgae}}
- Name: HelloWorldAgain
Action: RunPowerShellCommand
Properties:
commandContent: |-
echo {{HelloWorld.stdout}}
exit 0