Somethingwhatever
Somethingwhatever

Reputation: 1348

How to fix Docker invalid reference format?

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.

Upvotes: 2

Views: 6956

Answers (2)

Somethingwhatever
Somethingwhatever

Reputation: 1348

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

Upvotes: 0

Paolo
Paolo

Reputation: 25989

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

Upvotes: 2

Related Questions