Learn the syntax and usage of YAML and Dockerfile commands for Image Builder components and templates.
Command syntax
Image Builder supports two command formats: YAML (Linux and Windows) and Dockerfile (Linux only).
Dockerfile commands are less flexible and limited to Linux. Use the YAML format when possible.
YAML and Dockerfile formats use the following syntax:
-
YAML: Define the
ParametersandTaskssections:Parameters: # Optional. Defines custom parameters. param1: # Required. The name of the parameter. Type: String # Required. The type of the parameter. Valid values: String, Number, and Boolean. DefaultValue: defaultValue # Optional. The default value of the parameter. If no default value is specified, you must explicitly pass a value when you use the image component in an image template. Tasks: # Required. Defines a list of tasks for the image component. The tasks are run in sequence. At least one task must be included. - Name: taskName1 # Required. The name of the task. Action: RunShellCommand # Required. The action for the task. For more information, see the YAML-format component commands. Properties: # The properties of the action. The available properties depend on the specified action. commandContent: echo {{ param1 }} # References a custom parameter. - Name: taskName2 Action: action2 Properties: action2Property1: {{ taskName1.stdout }} # References the output of taskName1.NoteReference defined parameters in task properties:
{{taskName1.stdout}} -
Dockerfile
-
Each line contains one command.
-
A command can span multiple lines. Add a backslash (\) at the end of each line to continue on the next line.
-
Supported commands
Image Builder supports the following commands for components and templates.
Component commands
YAML format
|
Command |
Syntax |
Description |
Output |
|
RunShellCommand |
|
|
|
|
RunPowerShellCommand |
|
|
|
|
InvokeCommand |
|
Runs a common command. |
|
|
OSSDownload |
|
|
None |
|
OSSUpload |
|
|
|
|
WebDownload |
|
Downloads a file from a web URL. |
|
|
Reboot |
|
Reboots the instance. |
Dockerfile format
|
Command |
Syntax |
Description |
|
RESTART |
|
|
|
RUN |
|
|
|
ENV |
|
Note
In the |
|
WORKDIR |
|
Sets the working directory. |
|
COPY |
|
Copies files. Note
Network files are downloaded with |
|
USER |
|
Sets the user for subsequent Note
|
|
LABEL |
|
|
|
CMD |
|
Specifies the command to run on startup. |
|
ENTRYPOINT |
|
Specifies the command to run on startup. Note
|
Template commands
|
Command |
Syntax |
Description |
|
COMPONENT |
|
Specifies a system or custom image component.
|
|
RESTART |
|
|
|
RUN |
|
|
|
ENV |
|
Note
In the |
|
WORKDIR |
|
|
|
COPY |
|
Note
Network files are downloaded with |
|
USER |
|
Note
|
|
LABEL |
|
|
|
CMD |
|
|
|
ENTRYPOINT |
|
Note
|
Command examples
The following examples show component and template commands for common use cases.
Component commands
Example 1: Use custom parameters
This component calculates (3x+2y+z)+(3x+2y+z) with custom parameters x, y, and z. See Example 1: Associate a template with a component and assign values to its custom parameters for the corresponding template command.
Parameters:
x:
Type: String
y:
Type: String
z:
Type: String
Tasks:
- Name: count
Action: RunShellCommand
Properties:
commandContent: echo $((3 * {{x}} + 2 * {{y}} + {{z}}))
- Name: result
Action: RunShellCommand
Properties:
commandContent: echo $(({{count.stdout}}+{{count.stdout}}))
Example 2: Configure a script from OSS
Build an image from a Linux script in OSS to create identically configured ECS instances. The OSSDownload and OSSUpload actions eliminate the need to hardcode AccessKey pairs.
Tasks:
- Name: ossdownload
Action: OSSDownload
Properties:
bucketName: <your_oss_bucket_name>
destinationDir: /home
objectName: <your_script_object_name>
- Name: setpermissions
Action: RunShellCommand
Properties:
commandContent: sudo chmod +x /home/<your_script_object_name>
- Name: createfile
Action: RunShellCommand
Properties:
commandContent: sudo touch /home/output.txt
- Name: setfilepermissions
Action: RunShellCommand
Properties:
commandContent: sudo chmod 666 /home/output.txt
- Name: result
Action: RunShellCommand
Properties:
commandContent: sudo bash /home/<your_script_object_name> &> /home/output.txt
- Name: ossupload
Action: OSSUpload
Properties:
bucketName: <your_oss_bucket_name>
fileToUpload: /home/output.txt
objectName: output.txt
Template commands
Example 1: Associate a component and assign parameters
Assign values to the x, y, and z parameters from Example 1: Use custom parameters in a component.
COMPONENT i-xxxxxxxxx --x 1 --y 2 --z 3
Example 2: Use the latest component version
For a component with versions 1.0.1, 1.0.2, and 1.0.3, specify 1.0.* to use the latest matching version (1.0.3).
COMPONENT acs:ecs:cn-hangzhou:<alibaba_cloud_account_id>:imagecomponent/<your_component_name>/1.0.*