Using Aliyun-CLI with Docker Very Easily

To run very easily aliyun-cli commands on Alibaba Cloud, I show you how to use the Docker image I created. This image is public on Hub Docker (devopstestlab/aliyun-cli).

This image embeds too:

  • the Serverless Framework:
docker-aliyun-cli git:(master) ✗ docker run devopstestlab/aliyun-cli serverless --version

The output is:

Framework Core: 2.3.0
Plugin: 4.0.4
SDK: 2.3.2
Components: 3.1.5
  • Node.js:
docker run devopstestlab/aliyun-cli node --version

The output:


One of the main topics is the credentials. There are several ways to use them. I chose an approach useful to run several commands in a not interactive way and to run commands from a CI/CD as GitLab.

You can check the Docker image is available and download it:

docker pull devopstestlab/aliyun-cli

The output is:

Using default tag: latest
latest: Pulling from devopstestlab/aliyun-cli
Digest: sha256:6e0478ce0d3b59beda06071ca0c4fc18675eb64e31df04ab0eabea2872718be0
Status: Downloaded newer image for devopstestlab/aliyun-cli:latest

Now, talk about the credentials.

The first step is to create a credentials file:

docker run -v $PWD/data:/root/.aliyun cli aliyun configure set --profile akProfile --mode AK --region eu-central-1 --access-key-id <ACCESS_KEY_ID> --access-key-secret <ACCESS_KEY_SECRET>

Please insert the credentials <ACCESS_KEY_ID> and the <ACCESS_KEY_SECRET> provided by Alibaba Cloud console when you create an user with a programmatic access.

A credentials file is created in the ./data/config.json file:

ls -l ./data/config.json

The output is:

-rw-------  1 bruno  staff  754 26 sep 08:57 ./data/config.json

The second step is to execute aliyun-cli commands by providing the credentials file. For example:

docker run -v $PWD/data:/root/.aliyun:ro cli aliyun ecs DescribeRegions

The output is:

{"RequestId":"3627EE31-D2F7-411A-89B7-122965DF5FD1","Regions":{"Region":[{"RegionId":"cn-qingdao","RegionEndpoint":"","LocalName":"华北 1"},{"RegionId":"cn-beijing","RegionEndpoint":"","LocalName":"华北 2"},{"RegionId":"cn-zhangjiakou","RegionEndpoint":"","LocalName":"华北 3"},{"RegionId":"cn-huhehaote","RegionEndpoint":"","LocalName":"华北 5"},{"RegionId":"cn-wulanchabu","RegionEndpoint":"","LocalName":"华北6(乌兰察布)"},{"RegionId":"cn-hangzhou","RegionEndpoint":"","LocalName":"华东 1"},{"RegionId":"cn-shanghai","RegionEndpoint":"","LocalName":"华东 2"},{"RegionId":"cn-shenzhen","RegionEndpoint":"","LocalName":"华南 1"},{"RegionId":"cn-heyuan","RegionEndpoint":"","LocalName":"华南2(河源)"},{"RegionId":"cn-chengdu","RegionEndpoint":"","LocalName":"西南1(成都)"},{"RegionId":"cn-hongkong","RegionEndpoint":"","LocalName":"香港"},{"RegionId":"ap-northeast-1","RegionEndpoint":"","LocalName":"亚太东北 1 (东京)"},{"RegionId":"ap-southeast-1","RegionEndpoint":"","LocalName":"亚太东南 1 (新加坡)"},{"RegionId":"ap-southeast-2","RegionEndpoint":"","LocalName":"亚太东南 2 (悉尼)"},{"RegionId":"ap-southeast-3","RegionEndpoint":"","LocalName":"亚太东南 3 (吉隆坡)"},{"RegionId":"ap-southeast-5","RegionEndpoint":"","LocalName":"亚太东南 5 (雅加达)"},{"RegionId":"ap-south-1","RegionEndpoint":"","LocalName":"亚太南部 1 (孟买)"},{"RegionId":"us-east-1","RegionEndpoint":"","LocalName":"美国东部 1 (弗吉尼亚)"},{"RegionId":"us-west-1","RegionEndpoint":"","LocalName":"美国西部 1 (硅谷)"},{"RegionId":"eu-west-1","RegionEndpoint":"","LocalName":"英国 (伦敦)"},{"RegionId":"me-east-1","RegionEndpoint":"","LocalName":"中东东部 1 (迪拜)"},{"RegionId":"eu-central-1","RegionEndpoint":"","LocalName":"欧洲中部 1 (法兰克福)"}]}}

Now, you can easily create a credentials file you can store in a secure location to create it each time you need. Then you can run several commands or use aliyun-cli to create an infrastructure from a CD as GitLab or anything else.

The source code of the Docker image is here:

Bruno Delb

Original Source:

Follow me to keep abreast with the latest technology news, industry insights, and developer trends.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store