Docker: invalid reference format**

Need some guidance. I am trying to deploy a container in remote server and used groovy script to do this task. I am getting error like below,

[2025-04-02T04:26:43.369Z] + ssh -o StrictHostKeyChecking=no -l ec2-user 13.127.63.170 ‘docker run -itd -p 80:80 475798544865.dkr.ecr.ap-south-1.amazonaws.com/my-jenkins-project:“${ECR_Tag}”’ [2025-04-02T04:26:43.369Z] docker: invalid reference format

Can someone please check and let me know what wrong is there with this command (marked in *) ?

Pipeline stage,

stage ('Docker-deploy-prod') {
            
            steps {
                echo "***********************************Starting on remote production server****************************"
                sshagent(['Production']) {
                sh '''
                ssh -o StrictHostKeyChecking=no -l ec2-user 13.127.63.170 'aws ecr get-login-password --region ap-south-1 | sudo docker login --username AWS --password-stdin 475798544865.dkr.ecr.ap-south-1.amazonaws.com'
                ***ssh -o StrictHostKeyChecking=no -l ec2-user 13.127.63.170 'docker run -itd -p 80:80 475798544865.dkr.ecr.ap-south-1.amazonaws.com/my-jenkins-project:"${dtag}"'***
                '''
               }
            }
        }

Two observations:

  • either the value of ${dtag} is ${ECR_TAG} or your log snippet does not originate from the pipeline where you shared the snippet from
  • You can not just quote the tag and expect it to be valid. Either you quote "<repo>:<tag>", or don’t quote <repo>:<tag> at all.

Normally in a shell quoting only the version tag would be valid, but if the variable is empty, only the colon will be kept and that is indeed invalid even if you quote the entire repo name with the version tag.

Right, there shouldn’t be double quotes in the output at all.

The single quotes wrapped around the ssh command argument prevent variable expansion.