I am trying to run docker inside a shell script. This is what my script looks like :-
#!/bin/bash
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin <account-id>.dkr.ecr.us-east-1.amazonaws.com
IMAGE=$(aws ecr describe-images --repository-name repo --query 'sort_by(imageDetails,& imagePushedAt)[-1].imageTags[0]')
echo $IMAGE
docker pull https://<account-id>.dkr.ecr.us-east-1.amazonaws.com/repo:$IMAGE
docker run -d -p 8080:8080 https://<account-id>.dkr.ecr.us-east-1.amazonaws.com/repo:$IMAGE
But when i run the script, i keep running into
docker: invalid reference format.
See 'docker run --help'.
and i’m not sure what i’m doing wrong. Any help will be appreciated.
2
Answers
It was failing because the image tag was being returned inside double quotes. Had to get the output in plain text using :-
aws ecr describe-images --repository-name repo --query 'sort_by(imageDetails,& imagePushedAt)[-1].imageTags[0]' --output text
From the docs:
so for the pull command you should use:
then for the run command, you should use: