Host Docker deployment

更新时间:
复制 MD 格式

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.

  1. 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 (select master). Enable Source Code Trigger and click Add.

  2. 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.

  1. In the Docker Deployment task, select an existing host group or create a new host group. Set Execution User to root and write a deployment script in the Deployment Script editor. For example, docker run $image, where $image references an upstream output or custom variable.

    Note

    You must install Docker on the host before deployment.

  2. Configure the Docker deployment script.

    1. To deploy from a private repository, define DOCKER_USERNAME and DOCKER_PASSWORD as pipeline variables. Go to and click New Variable.

      Enable the Secret switch for both variables to mask their values.

    2. 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
  3. 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 appname to flow-example as the container name. In the Variables section, set image to tag.$(DATETIME) and appname to flow-example. In the deployment policy, set the pause method to Pause for the first batch and the number of batches to 2.

    • Example command to run a Docker container:

      docker run -d --name ${appname} ${image}
  4. 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.