title: How to push Docker image to ECR in Jenkins?
body: <p>I am working with Jenkins. I am trying to push image to <a href="https://aws.amazon.com/ecr/" rel="nofollow noreferrer">ECR</a>. I am using local Docker to build the images.</p>
  <p>Below is my Jenkins file:</p>
  <pre><code>pipeline {
      agent any
  
      stages {
          stage('Build') {
              steps {
                  bat  'docker build -t sampleapp -f SampleApp/Dockerfile .'
              }
          }
          stage('Push image') {
           steps {
             withDockerRegistry([url: &quot;https://536703334988.dkr.ecr.ap-southeast-2.amazonaws.com/test-repository&quot;,credentialsId: &quot;ecr:ap-southeast-2:demo-ecr-credentials&quot;]) {
             bat 'docker push sampleapp:latest'
                 }
          }
          stage('Deploy') {
              steps {
                  echo 'Deploying....'
              }
          }
      }
  }
  </code></pre>
  <p>In the above code, I am able to build and create an image. In the second stage, I am facing the issues. I am getting the below error:</p>
  <blockquote>
  <pre><code>$ docker login -u AWS -p ******** https://536703334988.dkr.ecr.ap-southeast-2.amazonaws.com/test-repository
  
  WARNING! Using --password via the CLI is insecure. Use --password-stdin.  
  Login Succeeded
  C:\Program Files (x86)\Jenkins\workspace\SampleAppPipeLine&gt;docker push sampleapp:latest 
  The push refers to repository [docker.io/library/sampleapp]
  a160522d6d0e: Preparing
  2e2c2606bd45: Preparing
  9b0a482c69b1: Preparing
  995a0cc6a5f6: Preparing
  c1b55dcb46c2: Preparing
  cf5b3c6798f7: Preparing
  cf5b3c6798f7: Waiting
      
  denied: requested access to the resource is denied
  </code></pre>
  </blockquote>
  <p>Can someone help me to fix this issue? Any help would be appreciated.<br />
  Thanks.</p>