Community

Blog
×
Community Blog Alibaba Cloud Toolbox - Running CLI in Docker

Alibaba Cloud Toolbox - Running CLI in Docker

The Alibaba Cloud Command Line Interface (CLI) is a unified tool that lets you control multiple services from the command line and automate them through scripts.

The Alibaba Cloud Command Line Interface (CLI) is a unified tool to manage your Alibaba Cloud services. With just one tool to download and configure, you can control multiple Alibaba Cloud services from the command line and automate them through scripts.

The CLI uses the SDK of various products internally to achieve the intended results. This installation can be hard to maintain considering the frequent releases of new SDK versions. This can also be cumbersome if you don't have access to a machine with the pre-requisites installed.

Docker comes in handy in this situation. The key benefit of Docker is that it allows users to package an application with all its dependencies into a standardized unit for software development. Unlike virtual machines, containers do not have the high overhead and hence enable more efficient usage of the underlying system and resources.

This document explains a pre-packaged Alibaba Cloud CLI Docker image that could be used to launch the CLI at will. It also discusses a way to make the container data persistent.

Prerequisites

  1. A machine with Docker installed. If you don't know how to do this, please refer to this tutorial.
  2. A working internet connection.

Getting Started

To get started, the Alibaba Cloud CLI Docker image needs to be fetched. Depending on your use case run one of the commands below (this will also fetch the latest image if one had not been fetched earlier):

Interactive mode:

docker run -ti aliyunca/aliyuncli-python-toolbox:latest sh

Detached mode:

docker run -dti aliyunca/aliyuncli-python-toolbox:latest sh

For both of these invocations, the CLI must then be configured:

# configure the CLI

$ aliyuncli configure

Aliyun Access Key ID [None]: my_access_id

Aliyun Access Key Secret [None]: mypassword

Default Region Id [None]:

Default output format [None]:

# make calls to Aliyun!

$ aliyuncli ecs

usage: aliyuncli <command> <operation> [options and parameters]

[ecs] valid operations as follows:

ActivateRouterInterface               | AddTags  

AllocateEipAddress                     | AllocatePublicIpAddress

ApplyAutoSnapshotPolicy          | AssociateEipAddress

AssociateHaVip                          | AttachDisk

....



# get some help regarding the function

aliyuncli ecs DescribeImages help

Note: The docker image can be configured to have the initial CLI configuration to be persisted. This should only be done in computers that the user has trust in. The parameter highlighted needs to be replaced.

Run the below command to pass the local folder reference that will store the CLI parameters

docker run -dti \

      -v {Full local folder path}:/root/.aliyuncli \

      aliyunca/aliyuncli-python-toolbox:latest sh

Environmental variables are also honored:

docker run -dti \

      --env ALI_ACCESS_KEY={API Key} \

      --env ALI_ACCESS_SECRET={API Secret} \

      --env ALI_DEFAULT_REGION=ap-southeast-1 \

      --env ALI_OUTPUT_FORMAT=json \

      aliyunca/aliyuncli-python-toolbox:latest sh

Conclusion

This document explains a simple way to access the Alibaba Cloud CLI without going through the complexities of maintaining an environment on its own. This will also free the host computer from the dependencies that will be installed as part of the CLI installation.

0 0 0
Share on

Sabith

9 posts | 3 followers

You may also like

Comments

Sabith

9 posts | 3 followers

Related Products