×
Community Blog Using Aliyun-CLI with Docker Very Easily

Using Aliyun-CLI with Docker Very Easily

This article shows a way to use very easily a Docker image to run aliyun-cli commands on Alibaba Cloud.

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:

v14.11.0

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
docker.io/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":"ecs.aliyuncs.com","LocalName":"华北 1"},{"RegionId":"cn-beijing","RegionEndpoint":"ecs.aliyuncs.com","LocalName":"华北 2"},{"RegionId":"cn-zhangjiakou","RegionEndpoint":"ecs.cn-zhangjiakou.aliyuncs.com","LocalName":"华北 3"},{"RegionId":"cn-huhehaote","RegionEndpoint":"ecs.cn-huhehaote.aliyuncs.com","LocalName":"华北 5"},{"RegionId":"cn-wulanchabu","RegionEndpoint":"ecs.cn-wulanchabu.aliyuncs.com","LocalName":"华北6(乌兰察布)"},{"RegionId":"cn-hangzhou","RegionEndpoint":"ecs.aliyuncs.com","LocalName":"华东 1"},{"RegionId":"cn-shanghai","RegionEndpoint":"ecs.aliyuncs.com","LocalName":"华东 2"},{"RegionId":"cn-shenzhen","RegionEndpoint":"ecs.aliyuncs.com","LocalName":"华南 1"},{"RegionId":"cn-heyuan","RegionEndpoint":"ecs.cn-heyuan.aliyuncs.com","LocalName":"华南2(河源)"},{"RegionId":"cn-chengdu","RegionEndpoint":"ecs.cn-chengdu.aliyuncs.com","LocalName":"西南1(成都)"},{"RegionId":"cn-hongkong","RegionEndpoint":"ecs.aliyuncs.com","LocalName":"香港"},{"RegionId":"ap-northeast-1","RegionEndpoint":"ecs.ap-northeast-1.aliyuncs.com","LocalName":"亚太东北 1 (东京)"},{"RegionId":"ap-southeast-1","RegionEndpoint":"ecs.aliyuncs.com","LocalName":"亚太东南 1 (新加坡)"},{"RegionId":"ap-southeast-2","RegionEndpoint":"ecs.ap-southeast-2.aliyuncs.com","LocalName":"亚太东南 2 (悉尼)"},{"RegionId":"ap-southeast-3","RegionEndpoint":"ecs.ap-southeast-3.aliyuncs.com","LocalName":"亚太东南 3 (吉隆坡)"},{"RegionId":"ap-southeast-5","RegionEndpoint":"ecs.ap-southeast-5.aliyuncs.com","LocalName":"亚太东南 5 (雅加达)"},{"RegionId":"ap-south-1","RegionEndpoint":"ecs.ap-south-1.aliyuncs.com","LocalName":"亚太南部 1 (孟买)"},{"RegionId":"us-east-1","RegionEndpoint":"ecs.aliyuncs.com","LocalName":"美国东部 1 (弗吉尼亚)"},{"RegionId":"us-west-1","RegionEndpoint":"ecs.aliyuncs.com","LocalName":"美国西部 1 (硅谷)"},{"RegionId":"eu-west-1","RegionEndpoint":"ecs.eu-west-1.aliyuncs.com","LocalName":"英国 (伦敦)"},{"RegionId":"me-east-1","RegionEndpoint":"ecs.me-east-1.aliyuncs.com","LocalName":"中东东部 1 (迪拜)"},{"RegionId":"eu-central-1","RegionEndpoint":"ecs.eu-central-1.aliyuncs.com","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

0 0 0
Share on

Bruno Delb

8 posts | 1 followers

You may also like

Comments