Failed to push to image (ECR)

I have been trying to push my built image into ECR. My ECR credentials are configured in the docker integration settings. From there on I have been facing issues in the pushing step and looked everywhere to make sense of the error, unfortunately, I cannot find anything that helps.

The error message:

Failed to push image

Logs:

name unknown: The repository with name ‘farisology/fyp-rahman’ does not exist in the registry with id ‘551650907187’

I would appreciate it if someone can point to me my mistake and help clarify to me what am missing here.

Here is my yaml file:

version: "1.0"
#Stages can help you organize your steps in stages
stages:
  - "clone"
  - "build"
  - "test"
  - "push"

steps:
  clone:
    title: "Cloning repository"
    type: "git-clone"
    repo: "farisology/fyp-rahman"
    # CF_BRANCH value is auto set when pipeline is triggered
    # Learn more at codefresh.io/docs/docs/codefresh-yaml/variables/
    revision: "${{CF_BRANCH}}"
    git: "github"
    stage: "clone"

  build:
    title: "Building Docker image"
    type: "build"
    image_name: "farisology/fyp-rahman"
    working_directory: "${{clone}}"
    tag: "${{CF_BRANCH_TAG_NORMALIZED}}"
    dockerfile: "Dockerfile"
    stage: "build"

  test:
    title: "Running test"
    type: "freestyle" # Run any command
    image: "ubuntu:latest" # The image in which command will be executed
    working_directory: "${{clone}}" # Running command where code cloned
    commands:
      - "ls"
    stage: "test"

  Push:
    type: "push"
    arguments:
      candidate: "${{build}}"
      registry: "farisology"
      stage: "push"

Hello.

Could you please provide the URL of the build that fails to push?

Have you also successfully pushed to this registry before using just plain docker commands (locally on your workstation)?

My bad I didn’t try pushing from local, I will try and report back.
For now here is the build URL: faild build in case there is any other issue.

What went wrong
So here is a description of the and how I managed to solve the issue.

In my push script, I am using the right repository name:

  Push:
type: "push"
arguments:
  candidate: "${{build}}"
  registry: "farisology"
  stage: "push"

The error message:

name unknown: The repository with name ‘farisology/fyp-rahman’ does not exist in the registry with id ‘551650907187’

So codefresh is trying to push to an ECR repository name ‘farisology/fyp-rahman’ meanwhile my actual repository name is ‘farisology’!!

I wonder why and how is that happening.

However, I have changed my image name in the Build step to be the ECR repository name. AND that worked fine.

Hello

I am glad it worked out. Yes there is much flexibility on naming. By default the build step creates a default image name and the push step re-uses it. I think this case works for most registries but AWS might be a bit different.

As you found out you can override the name in the build step. But you can also override the name in the push step as well :slight_smile:

The push step has an image_name that you can also use to customize the image name.

We are actually preparing several enhancements for build steps, which I think will simplify the situation a lot. Our roadmap for the new Docker image API and pipeline build step enhancements | Codefresh

@Kostis I did the same but this didnt work for me… my error is:

The push refers to repository [<accountid>.dkr.ecr.us-east-1.amazonaws.com/box/devops1983/python-flask-sample-app]        
EOF                                                                                                                        
[SYSTEM]                                                                                                                   
 Message             Failed to push image                                                                                  
                     <awsaccountid>.dkr.ecr.us-east-1.amazonaws.com/box/devops1983/python-flask-sample-app:2.0.0             
 Caused by           Container for operation: push. Failed with exit code: 1                                               
 Documentation Link  https://codefresh.io/docs/docs/codefresh-yaml/steps/push/                                             
 Exit code           1                                                                                                     
 Name                NonZeroExitCodeError      
pushtoecr:
    title: "pushing to Registry"
    type: "push"
    stage: "push"
    candidate: "${{build}}"
    tag: '2.0.0'
    registry: "amazon"

Hello.

As a first step you should try to push manually to your registry from your terminal using the standard docker push commands.

If that works, and Codefresh cannot push you need to open a ticket with us and include the URL of the build that has the issue so that they can investigate.

The error you are posting is generic and can mean different things (no such registry, wrong name in image, incorrect permissions etc).

ok sure i will try
registry exists and that user has admin access
image name also right…
i will still go back and try pushing using docker push commands

i could do this using docker push commands

ok. Then please open a support issue with us and be sure to include the URL of the build that shows the issue.