简体   繁体   中英

How to replace deprecated aws ecr get-login --registry-ids

I'm trying to pull one of the Amazon SageMaker Pytorch public images as per this example . In the example they use a shell script and a Dockerfile to pull-expand-build the container and push it to ECR. Here's the shell script:

# The name of our algorithm
algorithm_name=pytorch-extending-our-containers-cifar10-example

cd container

account=$(aws sts get-caller-identity --query Account --output text)

# Get the region defined in the current configuration (default to us-west-2 if none defined)
region=$(aws configure get region)
region=${region:-us-west-2}

fullname="${account}.dkr.ecr.${region}.amazonaws.com/${algorithm_name}:latest"

# If the repository doesn't exist in ECR, create it.

aws ecr describe-repositories --repository-names "${algorithm_name}" > /dev/null 2>&1

if [ $? -ne 0 ]
then
    aws ecr create-repository --repository-name "${algorithm_name}" > /dev/null
fi

# Get the login command from ECR and execute it directly
# ( PROBLEM 1 )
$(aws ecr get-login --region ${region} --no-include-email)

# Get the login command from ECR in order to pull down the SageMaker PyTorch image
# ( PROBLEM 2 )
$(aws ecr get-login --registry-ids 520713654638 --region ${region} --no-include-email)

# Build the docker image locally with the image name and then push it to ECR
# with the full name.

docker build  -t ${algorithm_name} . --build-arg REGION=${region}
docker tag ${algorithm_name} ${fullname}

docker push ${fullname}

However they use aws ecr get-login to get access to ECR. get-login is now deprecated in favour of get-login-password and running this shell script in awscli 2.0.3. fails. If I understood correctly then the first command (PROBLEM 1) can be replaced with:

$(aws ecr get-login-password --region ${region} | docker login --username AWS --password-stdin ${account}.dkr.ecs.${region}.amazonaws.com)

However the second command requires the flag --registry-ids , which is not recognized by get-login-password . How can I replace this command so that I could docker login to pull one of the SageMaker images from an external ECR registry?

I replaced (1) with:

$(aws ecr get-login-password --region ${region} |docker login --username AWS --password-stdin ${account}.dkr.ecr.${region}.amazonaws.com)

And (2) with:

$(aws ecr get-login-password --region ${region} |docker login --username AWS --password-stdin 763104351884.dkr.ecr.${region}.amazonaws.com)

So the registry-ids replaced the {account}. Also looks like the old ids are off, I switched the 520713654638 into 763104351884, also switching the Dockerfiles import into:

FROM 763104351884.dkr.ecr.$REGION.amazonaws.com/pytorch-training:1.6.0-gpu-py36-cu101-ubuntu16.04

After that running the script pulled, built and pushed the docker succesfully and I could proceed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM