Todos os produtos
Search
Central de documentação

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

Última atualização: Jul 03, 2026

Use o docker para executar o Alibaba Cloud CLI em um ambiente isolado e seguro.

Pré-requisitos

  • docker 18,09 ou posterior instalado. Obter o docker.

  • Execute docker --version para verifique a instalação.

Visão geral

O fluxo de trabalho inclui as etapas a seguir:

  1. Crie um Dockerfile: arquivo de texto simples com os comandos necessários para compilar uma image.

  2. Compile uma image personalizada: execute docker build para crie uma image docker a partir do Dockerfile.

  3. Inicie um contêiner: execute docker run para iniciar um contêiner com base na image.

  4. Conecte-se ao contêiner: execute docker exec para acessar o contêiner em execução e usar o Alibaba Cloud CLI.

Etapa 1: Crie um Dockerfile

Procedimento

Crie um diretório e salve o conteúdo abaixo em um arquivo chamado Dockerfile:

FROM centos:latest

# Obtain and install Alibaba Cloud CLI. In this example, the latest version of Alibaba Cloud CLI is used.
# Download the installation package of Alibaba Cloud CLI.
RUN curl -SLO "https://aliyuncli.alicdn.com/aliyun-cli-linux-latest-amd64.tgz"
# Decompress the installation package.
RUN tar -xvzf aliyun-cli-linux-latest-amd64.tgz
# Delete the installation package.
RUN rm aliyun-cli-linux-latest-amd64.tgz
# Move the executable file aliyun to the /usr/local/bin directory.
RUN mv aliyun /usr/local/bin/

Observação

  • Nomeie o arquivo como Dockerfile (D maiúsculo, sem extensão). Cada diretório pode conter apenas um Dockerfile.

  • Se você usar um processador ARM, como o Apple M1, altere a URL de download para https://aliyuncli.alicdn.com/aliyun-cli-linux-latest-arm64.tgz.

  • O exemplo anterior usa CentOS. Para Alpine Linux, use o seguinte Dockerfile:

    Exemplo de Dockerfile para Alpine Linux

    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.
    # Download the installation package of Alibaba Cloud CLI.
    RUN wget https://aliyuncli.alicdn.com/aliyun-cli-linux-latest-amd64.tgz
    # Decompress the installation package.
    RUN tar -xvzf aliyun-cli-linux-latest-amd64.tgz
    # Delete the installation package.
    RUN rm aliyun-cli-linux-latest-amd64.tgz
    # Move the executable file aliyun to the /usr/local/bin directory.
    RUN mv aliyun /usr/local/bin/
    
    # If you use Alpine Linux, you must 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

Etapa 2: Compilar uma image personalizada

  1. No diretório do Dockerfile, compile uma image docker chamada aliyuncli:

    docker build --tag aliyuncli .
  2. Saída esperada:

    image

Etapa 3: Iniciar um contêiner

  1. Inicie um contêiner docker a partir da image personalizada:

    docker run -it -d --name mycli aliyuncli
  2. Aguarde o retorno do id do contêiner.

    image

Etapa 4: Conectar-se ao contêiner

  1. Conecte-se ao contêiner em execução:

    docker exec -it mycli /bin/sh
  2. Execute aliyun version no contêiner para verifique a instalação da CLI.

    image

Próximos passos

Após conectar-se ao contêiner, Configure perfis do Alibaba Cloud CLI e Gere e execute comandos para gerencie seus recursos cloud.