Alibaba Cloud Command Line Interface (CLI) is a tool that is used to manage and use Alibaba Cloud resources on a command-line interface. Alibaba Cloud CLI is written in Go and built on Alibaba Cloud APIs. This topic describes how to run Alibaba Cloud CLI in a Docker container.

Prerequisites

Install Docker 18.09 or later on your on-premises server.

Procedure

  1. Create a directory on the desktop or on the server. Save the following code to a plaintext file named Dockerfile:
    FROM centos:latest
    
    # Obtain and install Alibaba Cloud CLI. We recommend that you install the latest version of Alibaba Cloud CLI. In this example, Alibaba Cloud CLI V3.0.124 is used.
    RUN curl -SLO "https://aliyuncli.alicdn.com/aliyun-cli-linux-3.0.124-amd64.tgz"
    RUN tar -xvzf aliyun-cli-linux-3.0.124-amd64.tgz
    RUN rm aliyun-cli-linux-3.0.124-amd64.tgz
    RUN mv aliyun /usr/local/bin/
    Note
    • A Docker file must be named Dockerfile, which starts with the uppercase letter D and has no file name extension. Only one Docker file can be saved in each directory.
    • In this example, CentOS is used. If you want to use Alpine Linux, replace the previous code with the following code in the Dockerfile file:
      FROM alpine:latest
      
      # Install the jq tool to display the command output in the JSON format.
      RUN apk add --no-cache jq
      
      # Obtain and install Alibaba Cloud CLI.
      RUN wget https://aliyuncli.alicdn.com/aliyun-cli-linux-3.0.124-amd64.tgz
      RUN tar -xvzf aliyun-cli-linux-3.0.124-amd64.tgz
      RUN rm aliyun-cli-linux-3.0.124-amd64.tgz
      RUN mv aliyun /usr/local/bin/
      
      # If you use Alpine Linux, run the following command to create a separate symbolic link to lib64 dynamic libraries.
      RUN mkdir /lib64 && ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2
    • In this example, Alibaba Cloud CLI V3.0.124 is used. We recommend that you use the latest version of Alibaba Cloud CLI.
  2. In the directory, run the docker build --tag aliyuncli . command to build a Docker image named aliyuncli.
    Note The period (.) at the end of the command notifies Docker to create a Docker image in the current directory. If the period (.) is omitted, an error occurs.
  3. After you create the Docker image, run the following command to start a Docker container:
    docker run -it -d --name aliyuncli aliyuncli
    Note In the command, the first aliyuncli is the container name. You can specify a custom name. The second aliyuncli is the image name, which must be the same as the name of the image that you want to use. In this example, the image is named aliyuncli in the previous step.
  4. Run the following command to connect to the Docker container:
    docker exec -it aliyuncli /bin/sh