This template builds a Docker image, pushes it to ACR, and deploys it to multiple ECS instances. You can build on existing ECS instances or a temporary pay-as-you-go instance that is automatically released after the build. Both ACR Enterprise Edition and Personal Edition are supported.
Prerequisites
-
An ECS instance with public network access is available. Create an instance, Enable the public network.
-
An ACR instance (Personal Edition or Enterprise Edition) is available. Container Registry (ACR), Differences between Personal Edition and Enterprise Edition instances, Create a Personal Edition instance.
How it works
-
When you specify a code source (OSS or Git), OOS generates a temporary URL to pull the code.
-
After building the image, OOS connects to ACR and pushes it to the specified repository.
-
OOS pulls the image from ACR and deploys it as a Docker container to the target ECS instances in batches.
Example
Prepare the code source
This example uses a sample Spring Boot project. The code is available in Gitee and GitHub repositories. Before you start, fork the project to your own repository.
-
Gitee: Gitee sample code (Recommended for users in the Chinese mainland)
-
GitHub: GitHub sample code (Recommended for users outside the Chinese mainland)
Create a template
-
Log on to the CloudOps Orchestration Service console.
-
In the left-side navigation pane, choose , and then click Create Template.
-
In the Building and Deployment section, select the Build and Push Image to ACR and Deploy sample template, and then click Next.
-
On the Process Configuration tab, configure the template parameters, and then click Create Template.
-
Specify a code source to generate a temporary authorization link for pulling the code.
This example uses Gitee as the code source. Enter the Owner, Organization, repository, and branch for your repository.
Note-
If you have not authorized Alibaba Cloud to read your repositories from GitHub or Gitee, click Go to Authorization to grant access.
-
If you have already forked the sample code, your repositories are automatically listed in the repository drop-down list. Select the forked repository.

-
-
Build a Docker image and push it to ACR.
-
Specify the code source, select the ECS instance for the build, and then configure the build script as needed.

-
Code Source and Code Source URL: Set Code Source to
git. Code Source URL defaults toauthorizedUrlfrom the previous task. -
Select the ECS instance for the build: Choose Build on an existing ECS instance or Start a temporary ECS instance for the build.
NoteIf you select Start a temporary ECS instance for the build, the instance is billed on a pay-as-you-go basis. OOS automatically checks if Docker is installed on the ECS instance. If not, OOS installs Docker Community Edition for you.
-
Build Configurations: Optional pre-build commands. Not needed if all steps are in the Dockerfile.
-
-
Configure the Docker build and the push to an ACR repository.
OOS runs
docker build. Specify theDockerfilepath and context path.
-
Dockerfile Path: Path to the Dockerfile, relative to the code repository root. For example, enter Dockerfile if it is in the root directory.

-
Context Path: Context path for
docker build, relative to the code repository root. Defaults to the Dockerfile directory if empty. -
Container Registry Type: Select the ACR edition to which you want to push the image.
Container registry type
Description
Related links
Personal Edition
Select your username, password, and target repository.
Enterprise Edition
Select the Container Registry instance ID, namespace, and repository.
Specify an image tag. The default uses the current date and execution ID. To push over the internal network, Configure access control for a VPC.
-
-
-
Pull the image from ACR and deploy it.
-
Select the target ECS instances and specify the image information to pull.

-
Target Instance: Select one or more ECS instances for deployment. Multiple selection methods are available.
-
Image information: Select the ACR type used in the previous step. OOS auto-populates
imageVersion,username,password,acrId,namespace, andrepoNamefrom the previous task output.NotePulling an image over an internal network requires the same VPC access control configuration as pushing. Configure access control for a Virtual Private Cloud (VPC).
-
-
Specify Docker run options.
For example, enter
-p 8080:8080. OOS appends these options to thedocker runcommand.
docker run -p 8080:8080 <image_name>NoteThe
--nameoption is unavailable. OOS assigns a container name based on the ACR repository name and automatically stops any existing container with the same name before deploying a new version. This way, after you push a new image version to the ACR repository, you can run the template again without having to manually stop the previous container. -
(Optional) Configure concurrency control for batch deployment across ECS instances.
-
-
Click Create Template.
-
Run the template
-
Log on to the CloudOps Orchestration Service console.
-
In the left-side navigation pane, choose .
-
On the custom task template page, find the template that you created and click Create an execution in the Actions column.
-
In the Basic Information step, configure the parameters and click Next: Set Parameters.
-
In the Parameter Settings step, if no changes are needed, click Next: Confirm.
-
Click Create.
On the task execution management page, a status of Successful indicates that the execution is complete.

-
Log on to the ECS console.
-
Find the ECS instance you selected and connect to it remotely.
For more information, see Log on to a Linux instance by using Workbench.
-
Verify the deployment:
curl http://localhost:8080/helloA successful response confirms the deployment.

Run
docker psto view running containers.
What to do next
After updating your code, push it to the Git repository and rerun this CI/CD template. OOS automatically stops the current container, builds a new image, pushes it to ACR, and deploys the latest version to the target ECS instances in batches. You can modify the template before rerunning it.