Alibaba Cloud DevOps Flow can build container images in pipeline jobs and deploy them to hosts using Docker.
Create a Docker deployment pipeline
On the Flow home page, click New Pipeline and select the Java · Test, build image template.
-
In the Pipeline Source stage, click Add Pipeline Source and select Codeup as the code source. Configure the service connection, code repository (select
springboot), and default branch (selectmaster). Enable Source Code Trigger and click Add. -
In the Build Image stage, click the Build and push images to ACR (Personal Edition) task. Select an authorized service connection
Set the tag to
${DATETIME}to auto-generate a timestamp. For Image Cache, select Remote Cache.
Configure a Docker deployment job
In a New Stage, click New Task and select .
In the task selection panel, choose Deployment on the left, then select the Docker Deployment task.
-
In the Docker Deployment task, select an existing host group or create a new host group. Set Execution User to
rootand write a deployment script in the Deployment Script editor. For example,docker run $image, where$imagereferences an upstream output or custom variable.NoteYou must install Docker on the host before deployment.
-
Configure the Docker deployment script.
-
To deploy from a private repository, define
DOCKER_USERNAMEandDOCKER_PASSWORDas pipeline variables. Go to and click New Variable.Enable the Secret switch for both variables to mask their values.
-
Add the following login command to the deployment script. Replace the registry address with your repository URL.
echo ${DOCKER_PASSWORD} | docker login --username ${DOCKER_USERNAME} --password-stdin registry.cn-hangzhou.aliyuncs.com
-
-
Add variables. Two types are available:
-
Upstream output variables: Reference build artifacts from upstream tasks (Alibaba Cloud images or custom images). Configure the output variable
image. -
Custom variables: Injected as environment variables on the host during execution. For example, set
appnametoflow-exampleas the container name. In the Variables section, setimagetotag.$(DATETIME)andappnametoflow-example. In the deployment policy, set the pause method to Pause for the first batch and the number of batches to2. -
Example command to run a Docker container:
docker run -d --name ${appname} ${image}
-
-
Configure a deployment policy to minimize the impact of unstable releases.
Run the pipeline and view deployment details
After the pipeline completes, go to and click Deployment Details to view deployment batches and logs. The details page shows the task status as Completed, the target host 10.0.0.26 online with instance ID i-bp13r1mbmowyr79fbi1m and instance name with-flow-ecs. Click Logs in the Actions column to view deployment logs.