本站文章总数为:165
Search Posts

aliyun CLI配置多个账户profile 登陆多个仓库提交镜像

内容纲要

需求产生

项目有正式环境测试环境,两个环境的Access Key ID & Secret也都不一样
最开始登陆一个就会把另一个顶掉
再次使用就要aliyun configure重新交互填写Access Key ID & Secret

$ aliyun configure
Configuring profile 'default' ...
Aliyun Access Key ID [None]: xxxxxxxxxxx
Aliyun Access Key Secret [None]: xxxxxxxxxxx
Default Region Id [None]: ap-northeast-1
Default output format [json]: json
Default Language [zh]: zh

$ password=$(aliyun cr GetAuthorizationToken --region ap-northeast-1 --InstanceId 'cri-xxxxxxxxxxx' --version 2018-12-01 --force | jq .AuthorizationToken | tr -d '"')
$ docker login --username=cr_temp_user --password=$password staging-legolas-registry.ap-northeast-1.cr.aliyuncs.com

需求解决

后续记得亚马逊 aws configure –profile test可以配置到profile
所以aliyun应该也可以
aliyun configure加上–profile lv2test
临时密码password生成也加上–profile lv2test

$ aliyun configure --profile lv2test
Configuring profile 'default' ...
Aliyun Access Key ID [None]: xxxxxxxxxxx
Aliyun Access Key Secret [None]: xxxxxxxxxxx
Default Region Id [None]: ap-northeast-1
Default output format [json]: json
Default Language [zh]: zh

$ password=$(aliyun cr GetAuthorizationToken  --profile lv2test --region ap-northeast-1 --InstanceId 'cri-xxxxxxxxxxx' --version 2018-12-01 --force | jq .AuthorizationToken | tr -d '"')
$ docker login --username=cr_temp_user --password=$password staging-legolas-registry.ap-northeast-1.cr.aliyuncs.com
[root@iZuf6hegfy8iwwureeshurZ ~]# aliyun configure list
Profile   | Credential         | Valid   | Region           | Language
--------- | ------------------ | ------- | ---------------- | --------
default   | AK:***hyT          | Valid   | ap-northeast-1   | zh
lv2test   | AK:***1UG          | Valid   | ap-northeast-1   | zh
lv2 *     | AK:***hyT          | Valid   | ap-northeast-1   | zh

如果需要登录lv2 就–profile lv2
这样提交正式镜像 测试镜像就互不冲突了

相关官方文档

阿里云CLI 说明
https://help.aliyun.com/document_detail/121258.html?spm=a2c4g.121193.0.0.121f6991q2MrL4
阿里云访问凭证管理 >> GetAuthorizationToken – 获取用于登录实例的临时账号和临时密码
https://www.alibabacloud.com/help/zh/acr/developer-reference/api-cr-2018-12-01-getauthorizationtoken

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注