All Products
Search
Document Center

Alibaba Cloud CLI:Run Alibaba Cloud CLI in a Docker container

Last Updated:Apr 22, 2024

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

Docker 18.09 or later is installed on your local computer.

Procedure

  1. Create a directory on the desktop or any other location. Save the following code to a plaintext file named Dockerfile:

    FROM centos:latest
    
    # Obtain and install Alibaba Cloud CLI. In this example, the latest version of Alibaba Cloud CLI is used.
    RUN curl -SLO "https://aliyuncli.alicdn.com/aliyun-cli-linux-latest-amd64.tgz"
    RUN tar -xvzf aliyun-cli-linux-latest-amd64.tgz
    RUN rm aliyun-cli-linux-latest-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 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-latest-amd64.tgz
      RUN tar -xvzf aliyun-cli-linux-latest-amd64.tgz
      RUN rm aliyun-cli-linux-latest-amd64.tgz
      RUN mv aliyun /usr/local/bin/
      
      # If you use Alpine Linux, run the following command to create a separate symbolic link that points to the lib64 dynamic library.
      RUN mkdir /lib64 && ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2
    • If you use an ARM processor such as Apple M1, change the download address to https://aliyuncli.alicdn.com/aliyun-cli-linux-latest-arm64.tgz.

  2. Run the following command in the directory to build a Docker image named aliyuncli.

    docker build --tag aliyuncli .
  3. After the Docker image is created, 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