I am tryong 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.
CodePudding user response:
From the docs:
The image name format should be registry/repository[:tag] to pull by tag, or registry/repository[@digest] to pull by digest.
so for the pull command you should use:
$ docker pull <account-id>.dkr.ecr.us-east-1.amazonaws.com/repo:$IMAGE
then for the run command, you should use:
$ docker run -d -p 8080:8080 <account-id>.dkr.ecr.us-east-1.amazonaws.com/repo:$IMAGE
CodePudding user response:
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