ECR是AWS是镜像仓库产品。
不同主体账号的ECR是不能相登录的,当需要部署同一个镜像的时候就很麻烦,可以配置密钥登录。
创建akckIAM---》创建用户--》点进用户--》安全证书--》创建访问密钥
aws configure测试的服务器是A主体账号下的,先配置A账号的akck:
[root@ip-xxx ~]# aws configure # 不指定用户会设置成默认用户,会被覆盖 AWS Access Key ID [None]: AKIAYCxxxxx AWS Secret Access Key [None]: W6VQ4g9xxxxx Default region name [None]: cn-northwest-1 # 所用的aws区域 Default output format [json]: json # 用的默认json
再配置B账号的akck:
[root@ip-xxxx ~]# aws configure --profile Btest # 用 --profile 指定用户 AWS Access Key ID [None]: AKIASMxxxxx AWS Secret Access Key [None]: ExDBEW1kZUwsxxxxx Default region name [None]: cn-northwest-1 Default output format [None]: json
查看aws configure,会是默认用户akck信息,如果再次aws configuer,这里会被覆盖
[root@ip-xxxx ~]# aws configure list
Name Value Type Location
---- ----- ---- --------
profile None None
access_key ****************NF3I shared-credentials-file
secret_key ****************3gi1 shared-credentials-file
region cn-northwest-1 config-file ~/.aws/config
用--profile指定用户
[root@ip-xxxx ~]# aws configure list --profile Btest
Name Value Type Location
---- ----- ---- --------
profile szeastroc manual --profile
access_key ****************ZCHK shared-credentials-file
secret_key ****************S771 shared-credentials-file
region cn-northwest-1 config-file ~/.aws/config
登录ECR
登录本账号主体不需要--profile
aws ecr get-login-password --region cn-northwest-1 | docker login --username AWS --password-stdin 55xxxxxx.dkr.ecr.cn-northwest-1.amazonaws.com.cn
A账号主体服务器指定使用B账号的akck登录B账号的ECR,需要使用--profile切换用户
aws ecr get-login-password --profile Btest --region cn-northwest-1 | docker login --username AWS --password-stdin 1x3xxxxx.dkr.ecr.cn-northwest-1.amazonaws.com.cn 拉取镜像 docker pull 163xxx.dkr.ecr.cn-northwest-1.amazonaws.com.cn/xxx:1



