Deploy applications from Docker images stored in Container Registry (ACR) Personal or Enterprise Edition.
To deploy from a third-party image repository, use a command-only deployment.
How it works
-
If you deploy to an ESS scaling group, scaling activities are paused during the deployment. The activities automatically resume after the deployment is complete, regardless of whether it succeeds or fails.
-
The deployment process first stops the old version and then starts the new one. Each deployment runs the stop script before it runs the start script.
-
The Docker image is automatically pulled to the Elastic Compute Service (ECS) instance during deployment. Do not include an image pull command in the start script.
-
Create and publish a deployment.
Specify the application's source file location in OSS, along with the start and stop scripts.
Create a release task, select a release mode, and publish the deployment to the target application group.
-
Automated deployment flow.
-
Retrieves the deployment information. This includes the Docker image details and the application's start and stop scripts.
-
Pulls the Docker image from the image repository to the ECS instance.
-
Runs the stop script to stop the old version of the application.
-
Runs the start script to start the new version of the application.
-
Usage notes
-
Deployments are supported only on Linux instances.
-
The start and stop scripts must be shell scripts.
Procedure
-
Prepare the application, group, and ECS instances.
Before you deploy, create an application and a group in ECS Application Management. Then, add your ECS instances to the group.
-
If you do not have an ECS instance, go to the ECS console - Custom Launch page to create a Linux ECS instance.
The following example scripts are for these images. If you use a different image, you must modify the scripts accordingly.
-
Go to the ECS console - Application management page and click Create from Existing Resources to create an application and an application group, and import the ECS instance into the application group.
-
Install Docker on the ECS instances in the group. On the O&M tab of the application group, select ACS-ECS-BulkyConfigureOOSPackageWithTemporaryURL to install Docker in a batch.
If your ECS instance was created from a custom image, you cannot install extensions this way. You must remotely connect to the instance and manually install Docker.
-
-
Create a Docker image deployment.
-
Pull the sample image to your local machine, and then push the image to an ACR Enterprise Edition or ACR Personal Edition repository.
docker pull aliyun-computenest-opensource-registry.cn-hangzhou.cr.aliyuncs.com/default/aliyun-code-deploy:latest -
Go to the ECS console - Application management page. On the My Applications tab, click the name of your target application.
-
On the application details page, select the Deployment tab, and then click Create Deployment.
-
On the Create Deployment page, set Deployment Type to Docker Image, and configure the following key fields.
-
ACR instance information: Enter the ACR instance information. After you enter the image version, the system automatically generates an image address. Use this address in the application start script.
ImportantIf you use ACR Personal Edition, configure the username and password for your ACR Personal Edition in the advanced settings of the application details page.
-
Working directory: The execution directory for the application start and stop scripts. Example:
/root/deploy. -
Application start script: Replace
<Registry Address>with the actual address.### The Docker image is automatically pulled to the ECS instance during deployment. You can start the container directly. ### Start the current version of the container start_application() { image_name="<Registry Address>" container_name="my-container" docker run -d -p 8080:8080 --name ${container_name} ${image_name} } start_application -
stop_application() { # Query whether the container exists by the container name, and delete the container if it exists container_name="my-container" container_id=$(docker ps -aq -f name=${container_name}) if [ -n "$container_id" ]; then docker rm -f $container_id fi } stop_application
-
-
After you configure all parameters, click OK to save the deployment.
-
-
Go back to the deployment list, find the deployment that you created, and click Deploy. Select the target group and click OK to start the deployment.
-
Verify the result.
Navigate to the details page of the target instance. Click Connect and select Workbench. Follow the on-screen prompts to access the terminal.
-
Run the
curl http://localhost:8080/hellocommand. A response ofAlibaba Spring Sample!indicates a successful deployment.
Key fields
|
Field |
Description |
|
Container Registry region |
The region where the ACR instance is located. |
|
Container Registry instance ID |
ACR Enterprise Edition instance ID |
|
Namespace |
The namespace where the image repository is located. |
|
Repository name |
The name of the image repository. |
|
Image version |
The Docker image version to deploy. |
|
Pull image over private network |
If selected, the ACR instance and the ECS instance must be in the same Virtual Private Cloud (VPC), and you must configure access control for the VPC. |
|
Working directory |
The working directory for the application's start and stop scripts.
|
|
Application start script |
The Shell script used to start the application. |
|
Application stop script |
The shell script to stop the application. For example, the following script stops a container named
|