Docker can be deployed on Alibaba Cloud DevOps Flow. The final deployment objective is sourced from the image build artifacts of pipeline jobs. This topic describes how to use image build artifacts of pipeline jobs to deploy Docker.
Create a Docker deployment pipeline
On the Flow page, click Create Pipeline. In the dialog box that appears, select the Java Test, build image template.
In the Pipeline Source stage, click Add Pipeline Source, select Codeup as the code source type, add a service connection, and then configure parameters such as Code Repository.

In the Build Image stage, click Build and push images to ACR (Personal Edition). Select an authorized service connection, and specify the Region, Repository, Docker Tag, and Dockerfile. You can click the link to view the Dockerfile of the spring-boot repository for Alibaba Cloud DevOps Flow.

Configure a Docker deployment job
In New Stage, click Create Job. In the panel that appears, click the Deploy tab, and select Docker Deploy on VM to create a job.

For Docker Deployment, select an existing host group or click New Host Group.
NoteYou must install Docker on the host in advance.
Configure the Docker deployment script.
If the image that you deploy is from your private repository, you need to provide the logon authorization information. For security purposes, you can use the variable feature provided by Flow. You can add the
DOCKER_USERNAMEandDOCKER_PASSWORDvariables to specify the logon username and password. On the pipeline editing page, choose . On the Variables page, click Create Variable.
Run the
echo ${DOCKER_PASSWORD} | docker login --username ${DOCKER_USERNAME} --password-stdin registry.cn-hangzhou.aliyuncs.comcommand in the deployment script. In this command, you must specify the image repository based on your project information. Then, run the relevant command to perform operations on the image of your private repository. The following command is included in the deployment script and used to log on to the image repository.echo ${DOCKER_PASSWORD} | docker login --username ${DOCKER_USERNAME} --password-stdin registry.cn-hangzhou.aliyuncs.com
Add variables, which are divided into the following types:
Upstream output variables: The upstream output artifacts can be the build artifacts of Alibaba Cloud images or custom images. Configure the upstream output variable
image.Custom variables: When you run a command, variables are written to machine environment variables. This way, you can directly use the variables. For example, you can add a custom variable named
appnameto the deployment script, and assign the valueflow-exampleto the variable. The value is used as the container name.
The following command is a typical command in a deployment script and used to run a Docker container.
docker run -d --name ${appname} ${image}
Configure a deployment policy to prevent the negative impact of unstable releases on users and ensure stable business delivery.
Run the deployment job and view Docker deployment details
After the pipeline job is run, in the stage, click Deployment Details to view batches and their logs.