title: docker push with AWS CodeBuild fails with exit status 1
body: <p>I created my CodeBuild project triggered by CodePipeline and the 'docker push' step always fails with the 'Reason: exit status 1' error message</p>
  <p>Here are my build logs (replaced my org id by &lt;MY_ORG_ID&gt;):</p>
  <pre><code>[Container] 2021/06/12 14:39:47 Entering phase INSTALL
  [Container] 2021/06/12 14:39:47 Phase complete: INSTALL State: SUCCEEDED
  [Container] 2021/06/12 14:39:47 Phase context status code:  Message: 
  [Container] 2021/06/12 14:39:47 Entering phase PRE_BUILD
  [Container] 2021/06/12 14:39:47 Running command echo Logging in to Amazon ECR...
  Logging in to Amazon ECR...
  
  [Container] 2021/06/12 14:39:47 Running command aws ecr get-login-password --region eu-west-2 | docker login --username AWS --password-stdin &lt;MY_ORG_ID&gt;.dkr.ecr.eu-west-2.amazonaws.com
  WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
  Configure a credential helper to remove this warning. See
  https://docs.docker.com/engine/reference/commandline/login/#credentials-store
  
  Login Succeeded
  
  [Container] 2021/06/12 14:39:51 Running command docker push &lt;MY_ORG_ID&gt;.dkr.ecr.eu-west-2.amazonaws.com/reponame/core-service:latest
  The push refers to repository [&lt;MY_ORG_ID&gt;.dkr.ecr.eu-west-2.amazonaws.com/reponame/core-service]
  An image does not exist locally with the tag: &lt;MY_ORG_ID&gt;.dkr.ecr.eu-west-2.amazonaws.com/reponame/core-service
  
  [Container] 2021/06/12 14:39:51 Command did not exit successfully docker push &lt;MY_ORG_ID&gt;.dkr.ecr.eu-west-2.amazonaws.com/reponame/core-service:latest exit status 1
  [Container] 2021/06/12 14:39:51 Phase complete: PRE_BUILD State: FAILED
  [Container] 2021/06/12 14:39:51 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: docker push &lt;MY_ORG_ID&gt;.dkr.ecr.eu-west-2.amazonaws.com/reponame/core-service:latest. Reason: exit status 1
  </code></pre>
  <p>And here is my buildspec.yaml:</p>
  <pre><code>version: 0.2
  
  env:
    git-credential-helper: yes
  phases:
    pre_build:
      commands:
        - echo Logging in to Amazon ECR...
        - aws ecr get-login-password --region eu-west-2 | docker login --username AWS --password-stdin &lt;MY_ORG_ID&gt;.dkr.ecr.eu-west-2.amazonaws.com
    build:
      commands:
       - echo Pushing Docker image &lt;MY_ORG_ID&gt;.dkr.ecr.eu-west-2.amazonaws.com/reponame/core-service:latest
      - DOCKER_REPO=&lt;MY_ORG_ID&gt;.dkr.ecr.eu-west-2.amazonaws.com
      - IMAGE_TAG=${DOCKER_REPO}/reponame/core-service:${EKS_CLUSTER_NAME}-${CODEBUILD_RESOLVED_SOURCE_VERSION}-v${CODEBUILD_BUILD_NUMBER}
      - echo Set IMAGE TAG = $IMAGE_TAG
      - docker build --build-arg NODE_ENV=production --build-arg DOCKER_REPO=${DOCKER_REPO} -t $IMAGE_TAG core-service/.
    - docker push $IMAGE_TAG   
  </code></pre>
  <p>As many references point out, I have added this statement to the policy attached to the corresponding AWS CodeBuild service role but it still does not work.</p>
  <pre><code>{
    &quot;Statement&quot;: [
      ### BEGIN ADDING STATEMENT HERE ###
      {
        &quot;Action&quot;: [
          &quot;ecr:BatchCheckLayerAvailability&quot;,
          &quot;ecr:CompleteLayerUpload&quot;,
          &quot;ecr:GetAuthorizationToken&quot;,
          &quot;ecr:InitiateLayerUpload&quot;,
          &quot;ecr:PutImage&quot;,
          &quot;ecr:UploadLayerPart&quot;
        ],
        &quot;Resource&quot;: &quot;*&quot;,
        &quot;Effect&quot;: &quot;Allow&quot;
      },
      ### END ADDING STATEMENT HERE ###
      ...
    ],
    &quot;Version&quot;: &quot;2012-10-17&quot;
  }
  </code></pre>
  <p>I can run these steps manually but it always gives me this error on CodeBuild.</p>
  <p>Please, if you could help, there are similar threads out there but none could explain a solution for this one specifically. Thanks.</p>